• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

Check a String is SUBSEQUENCE of another String Find Minimum length for that ( DNA Matching )

August 12, 2014 by Dhaval Dave

Main DNA sequence(a string) is given (let say strDNA) and another string to search for(let say strPAT).
You have to find the minimum length window in strDNA where strPAT is subsequence.


Example :
strDNA = “BANANA”
strPAT = “ANNA”

Here ANNA is sub-sequence of BANANA (click sub-sequence to understand sub-sequence).
Length is 5 ANANA contains ANNA.

There are several ways to check for occurrence of string as subsequence of another string.
Through DP we can find more efficient answer for minimum length.
Considering simple case I have written code to check whether strPAT is subsequence of strDNA or not.

Thanks to Dhaval for suggesting this approach and Article

#include <stdio.h> 
main() { 
    char *x,*y;
    int count=0;
    int f=0;
    char a[]=”anna”;
    char b[]=”banana”;
x=a; y=b;
        while(*y){
           if(*x==*y){
               x++;
               f=1;
           }
           if(f==1)count++;
           *y++;
        }
if (*x!=’’) 
    printf(“n false (%s)n”,x);
else
    printf(“ntrue %dn”,count);

 }

You Can Check code at http://ideone.com/y4P2oI

Similar Articles

Filed Under: Amazon Interview Question, Flipkart Interview Questions, Interview Questions, problem Tagged With: Array, Dynamic Programming, string

Reader Interactions

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

Hackerearth : Counting Subarrays

N Petrol bunks or City arranged in circle. You have Fuel and distance between petrol bunks. Is it possible to find starting point so that we can travel all Petrol Bunks

Cisco Hiring Event 21st – 22nd Feb 2015

Microsoft BING Interview Experience

Coin Collection Dynamic Programming

Convert number to words java

Apriori algorithm C Code Data Mining

Given a sorted array and a number x, find the pair in array whose sum is closest to x

Puzzle : 100 doors in a row Visit and Toggle the door. What state the door will be after nth pass ?

C++ OOPs Part1

N teams are participating. each team plays twice with all other teams. Some of them will go to the semi final. Find Minimum and Maximum number of matches that a team has to win to qualify for finals ?

Inorder and Preorder traversals of a Binary Tree given. Output the Postorder traversal of it.

Fibonacci Hashing & Fastest Hashtable

Calculate price of parking from parking start end time prices

Trapping Rain Water

Introduction To Number Theory ( Part 1 )

Serialise Deserialise N-ary Tree

write a c program that given a set a of n numbers and another number x determines whether or not there exist two elements in s whose sum is exactly x

Binary Tree in Java

Maximum size of square sub matrix with all 1’s in a binary matrix

HackeEarth Flipkart’s Drone

flattens 2 D linked list to a single sorted link list

Printing Longest Common Subsequence

Find next greater number with same set of digits

25 horses 5 tracks Find 3 fastest puzzle

CodeChef Code SGARDEN

BlueStone E-commerce Interview Experience

C Program for TAIL command of UNIX

robot standing at first cell of an M*N matrix. It can move only in two directions, right and down. In how many ways, it can reach to the last cell i.e. (M, N) Code it

Difference between a LinkedList and a Binary Search Tree BST

Copyright © 2025 · Genesis Framework · WordPress · Log in