GeeksforGeeks » Interview Questions

Deciphering the key

(1 post)
  • Started 5 months ago by Anubhav
  1. Anubhav
    guest
    Posted 5 months ago #

    Alice invents a key (s1, s2, s3, ... , sk). Bob makes a guess (g1, g2, g3, .... gk).He is awarded one point for each si = gi. Each s1 is an integer with the range of 0<=s1<=11. Given a q guesses
    (g1, g2, g3, .... gk) b1
    (g1, g2, g3, .... gk) b2
    .
    .
    .
    (g1, g2, g3, .... gk) bq

    Can you state if there is a key possible. Given 0<=si<=11, 1<=k<=11, 1<=q<=8.
    For Example
    2 2 1 1 2
    1 1 2 2 1

    Answer to this will be Yes because there is a key possible let's say 2 1 1 3 which gives the desired scores.
    Another Example
    1 2 3 4 4
    4 3 2 1 1

    This has no key which gives the desired scores hence answer is NO
    I tried the brute force approach genearting n^k such keys where n is the range of si.But it gave Time Limit exceeding error.
    Its an interview puzzle. I have seen variants of this question but was not able to solve them.Can you tell me what should I read for such type of questions.


Reply

You must log in to post.

RSS feed for this topic