• 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

Find Percentage of Words matching in Two Strings

July 28, 2014 by Dhaval Dave

There are two strings s1 and s2. Find the maximum of percentage word matching from s1 to s2 and s2 to s1.
Where, percentage word matching= (Total words matched in s2/total number of words in s1) *100
Working code :
Simple Logic : tokenize One String into words.
Check whether word is part of another string.
PS : coding is tricky here as it consists of Strings and String functions.
First try by your self and then check here for reference.
Thanks to Dhaval for suggesting this approach and Article
#include <stdio.h>
#include <string.h>
 
int wordCount(char s1[]){
int i,wc=1;
 for(i=0;i<=strlen(s1);i++){
    if (s1[i]==’ ‘ ) wc++;
 }
return wc;
}//wordCount
 
int findPercentage(char s1[],char s2[],int n){
 int i=0,j=0,mc=0,wc1,wc2;
 char w1[n],w2[n];
 for(i=0;i<=strlen(s1);i++,j++){
     w1[j]=s1[i];
     if(s1[i]==’ ‘||s1[i]==”){w1[j]=”;j=-1;
        if(strstr(s2,w1))mc++;
     }//if
 }//for
 wc1=wordCount(s1);
 wc2=wordCount(s2);
 printf(“Common words = %d nC1 = %d % nC2 = %d %” ,mc, (mc*100)/wc1,(mc*100)/wc2);
}//findPercentage
 
int main(void) {
int max;
char s1[]=”This is sparta”;
char s2[]=”sparta is a country”;
max=strlen(s1)>strlen(s2)? strlen(s1): strlen(s2);
findPercentage(s1,s2,max);
return 0;
}
Working Code you can find at  : http://ideone.com/e.js/EdL7NH

Similar Articles

Filed Under: Amazon Interview Question, Interview Questions, problem Tagged With: 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

Rectangular chocolate bar Create at least one piece which consists of exactly nTiles tiles

Length of the longest substring without repeating characters

Doubly linked list

Maximum path sum between two leaves

Find an index i such that Arr [i] = i in array of n distinct integers sorted in ascending order.

Find Nearest Minimum number in left side in O(n)

Cisco Hiring Event 21st – 22nd Feb 2015

Adobe Interview Questions 8 month Exp

Check Binary Tree is Binary Search Tree or not

SAP Hiring Off-Campus General Aptitude

Find Pythagorean Triplets in an array in O(N)

Naurki.com Security Breach

DFS (Depth First Search)

Maximum difference between two elements s.t larger element appears after the smaller number

Print all nodes that are at distance k from a leaf node

Trie Dictionary

Amazon Interview On-Campus For Internship – 1

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

Minimum insertions to form a palindrome

Daughter’s Age VeryGood Puzzle

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

Printing intermediate Integers between one element & next element of array

‘N’ Story Building, with 1,2,3 steps how many ways can a person reach top of building.

Convert Decimal to Roman numbers / Romanizer HackerEarth Code

K’th Largest Element in BST when modification to BST is not allowed

Closed Parentheses checker

Client Server C program

Apriori algorithm C Code Data Mining

Stock Buy Sell to Maximize Profit

Stickler thief

Copyright © 2025 · Genesis Framework · WordPress · Log in