Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7046279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:37:53+00:00 2026-05-28T02:37:53+00:00

Alice invents a key (s 1 , s 2 , s 3 , …

  • 0

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<=si<=11.
Given a q guesses with their scores bi

(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

For the guess 2 2 1 1 the score is 2
For the guess 1 1 2 2 the score is 1
Because there is a key possible let’s say 2 1 1 3 which gives the desired scores.Hence the answer is yes

Another Example
1 2 3 4 4
4 3 2 1 1

For the guess 1 2 3 4 the score is 4
For the guess 4 3 2 1 the score is 1

This has no key which gives the desired scores hence answer is NO

I tried the brute force approach generating 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:37:53+00:00Added an answer on May 28, 2026 at 2:37 am

    I don’t know the best solution to this problem, but if you did a recursive search of the possible solution space, pruning branches which could not possibly lead to a solution, it would be much faster than trying all (n^k) keys.

    Take your example:

    1 2 3 4 4 -> 4
    4 3 2 1 1 -> 1

    The 3 possible values for g1 which could be significant are: 1, 4, and “neither 1 nor 4”. Choose one of them, and then recursively look at the possible values for g2. Choose one, and recursively look at the possible values for g3, etc.

    As you search, keep track of a cumulative score for each of the guesses from b1 to bq. Whenever you choose a value for a digit, increment the cumulative scores for all the guesses which have the same number in that position. Keep these cumulative scores on a stack (so you can back up).

    When you reach a point where no solution is possible, back up and continue searching a different path. If you back all the way up to g1 and no more paths are left to search, then the answer is NO. If you find a solution, then the answer is YES.

    When to stop searching a path and back up:

    • If the cumulative score of one of the guesses exceeds the given score
    • If the cumulative score of one of the guesses is less than the given score minus the number of levels left in the search tree (before you hit the bottom)

    This approach could still be very slow, especially if “k” was large. But again, it will be far faster than generating (n^k) keys.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a set of strings, say: Alice Bob C Ca Car Carol Caroling Carousel
Given this data: users id name == ==== 1 Alice 2 Bob 3 Carl
Say we have Alice and Bob. Alice sends Bob a message she encrypted with
I have two users Bob and Alice in Oracle, both created by running the
Let's say you have two Control s, Alice and Bob, and you want to
I'm new to Git. Let's say Alice and Bob had been developing their project
I am writing a packacge foobar which consists of the modules alice, bob, charles
I have a list of tuples. [ Bob: 3, Alice: 2, Jane: 1, ]
Alice & Bob are both secret quadruple agents who could be working for the
Data: $data = array('Alice', 'Bob', 'Carol', 'David', 'Elizabeth', 'Frank'); Method A: file_put_contents('filename.ext', implode(\n, $data)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.