• 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

Longest Increasing Subsequence

Count number of ways to reach a given score in a game

Difference between a LinkedList and a Binary Search Tree BST

Stock Buy Sell to Maximize Profit

Maximum occurred Smallest integer in n ranges

Find and print longest consecutive number sequence in a given sequence in O(n)

Trapping Rain Water

Regular Expression Matching

Number of Islands BFS/DFS

Sort an array according to the order defined by another array

Best Java Book | Top Java Programming Book for Beginners

SAP Hiring Off-Campus General Aptitude

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

Fibonacci Hashing & Fastest Hashtable

Find the number ABCD such that when multipled by 4 gives DCBA.

Doubly linked list

Code Chef PRGIFT Solution

Leetcode: Edit Distance

VMWare SDEII Interview

Word Break Problem

Python List

Find loop in Singly linked list

Find if a binary tree is height balanced ?

Find the kth number with prime factors 3, 5 and 7

C++ OOPs Part2

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

Generate next palindrome number

Right view of Binary tree

Memory Efficient LinkedList

LeetCode: Container With Most Water

Copyright © 2026 · Genesis Framework · WordPress · Log in