• 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

Find min element in Sorted Rotated Array (Without Duplicates)

Top 10 Interviews Techniqes for Campus Interview in IIT NIT BITS for MTech

Implement LRU Cache

LeetCode: Container With Most Water

Diagonal Traversal of Binary Tree

Linked List V/S Binary Search Tree

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

SAP Off Campus Hiring_ March 2015 Analytical Aptitude

Interfaces in C++ (Abstract Classes in C++)

Implement a generic binary search algorithm for Integer Double String etc

Find Percentage of Words matching in Two Strings

Templates in C++

Get Minimum element in O(1) from input numbers or Stack

SAP Interview Questions

Find min element in Sorted Rotated Array (With Duplicates)

Skiing on Mountains Matrix

Generate largest number arranging a no. of given non negative integer numbers

VMWare Openings

Best Java Book | Top Java Programming Book for Beginners

Coin Collection Dynamic Programming

building with N steps, we can take 1,2,3 steps calculate number of ways to reach at top of building

Search element in a matrix with all rows and columns in sorted order

25 horses 5 tracks Find 3 fastest puzzle

HackeEarth Flipkart’s Drone

SAP Off Campus Hiring_ March 2015 Verbal Skills

C++ OOPs Part1

Binary Tree Isomorphic to each other

Check if an array has duplicate numbers in O(n) time and O(1) space

Given array of 0’s and 1’s. All 0’s are coming first followed by 1’s. find the position of first 1

The Magic HackerEarth Nirvana solutions Hiring Challenge

Copyright © 2025 · Genesis Framework · WordPress · Log in