Dsa
Binary Search
Medium
Word Frequency Lookup
You are given a list of words along with their corresponding counts. The list of words is sorted alphabetically. You need to write a program to find the count of a given word using binary search. If the word is not found, return 0.
Input Format:
- The first line contains an integer w (1 <= w <= 1000), the number of words.
- The second line contains w space-separated words in sorted order.
- The third line contains w space-separated integers representing the counts of the corresponding words.
- The fourth line contains a word to search for.
Output Format:
- An integer representing the count of the given word, or 0 if not found.
Example:
Input:
4
apple banana orange pear
5 3 8 2
banana
Output:
3
Key concepts
binary_searchstringsearch
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now