Strings of Numbers Problem Statement

You are given two integers 'N' and 'K'. Consider a set 'X' of all possible strings of 'N' number of digits where all strings only contain digits ranging from 0 to 'K' inclusive. Your task is to determine a string of minimal length such that it includes every string from set 'X' as one of its substrings.

Example:

Input:
N = 2, K = 2
Output:
'X' = {00, 01, 02, 10, 11, 12, 20, 21, 22}

Explanation:

Find a string that contains all possible combinations of 2-digit numbers with digits from 0 to 2.

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 4
  • 0 ≤ K ≤ 9
  • Time Limit: 1 sec

Input:

Each test case contains two integers 'N' and 'K' denoting the number of digits in each number and the maximum value of digits respectively.

Output:

For each test case, print 1 if your solution contains all strings from the set, otherwise print 0.

Note:

  • If multiple solutions are possible, any one can be printed.
  • No need to handle input or output yourself, just implement the required function.
AnswerBot
6d

The task is to find a string of minimal length that includes every possible string of N digits with digits ranging from 0 to K as substrings.

  • Generate all possible strings of N digits with digits from ...read more

Help your peers!
Add answer anonymously...
TCS Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter