Algorithms and Data Structures

  • Profound Academy

    • Status
      • 1
      • 2
        Bitwise operations
      • 3
        Prefix Sums
      • 4
        Sliding window / Two pointers
      • 5
        Modular Arithmetic
      • 6
        Number Theory
      • 7
        Binary Search
      • 8
        Basic Sorting
      • 9
        Greedy Algorithms
      • 10
        Basic Dynamic Programming
      • 11
      • 12
        Linked LIst
      • 13
        Queue & Stack
      • 14
        Binary tree + BST
      • 15
        Divide & Conquer + Advanced Sorting
      • 16
      • 17
      • 18
        Graph Representation
      • 19

  • Search in Lex Fridman’s podcasts

    Lex Fridman hosts a very interesting podcast where he calls different guests like Elon Musk, Joe Rogan, Andrej Karpathy, and Vitalik Buterin to name a few. Both you and your friend Anna really enjoy watching the podcasts. When discussing the podcasts, you like talking about the number of views the podcast got and who was the guest. You’ve decided to write that information out and keep it as a list of pairs (guest, views). Now whenever Anna mentions a name of a guest, you can look at the list and find out the number of views that podcast got.
    notion image
    Can you write a program that would print the number of views for all the guests Anna was talking about?


    The first line of the input contains a single integer n (1 ≤ n ≤ 1000) - the number of podcasts you’ve kept as a list of pairs.
    The next 2n lines contain pairs of guests and views. First comes the name of the guest, then the number of views that the podcast obtained.
    The following line contains a single integer q (1 ≤ q ≤ n) - the number of questions Anna has about the podcast guests.
    The next q lines are the names of the guests Anna talks about.


    For each of the q questions, the program should print the number of views the podcast obtained.


    5 Elon Musk 6400000 Joe Rogan 6200000 Kanye West 4000000 Vitalik Buterin 4500000 Mark Zuckerberg 3800000 3 Elon Musk Mark Zuckerberg Joe Rogan
    6400000 3800000 6200000
    Disclaimer: This method of searching for the right answer is called a linear search. We’ll learn how to perform faster queries for different types of problems in a bit.


    Time limit: 1 seconds

    Memory limit: 512 MB

    Output limit: 1 MB

    To check your solution you need to sign in
    Sign in to continue