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
4mo

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!
Select
Add answer anonymously...

TCS Software Developer interview questions & answers

A Software Developer was asked 4d agoQ. What is Python?
A Software Developer was asked 3w agoQ. What is the process for synthesizing data to train a machine learning model with...read more
A Software Developer was asked 1mo agoQ. What is a string?

Popular interview questions of Software Developer

A Software Developer was asked 3w agoQ1. What is the process for synthesizing data to train a machine learning model with...read more
A Software Developer was asked 1mo agoQ2. What is a string?
A Software Developer was asked 2mo agoQ3. What is the concept of Zero Copy Cloning in Snowflake?

Top HR questions asked in TCS Software Developer

A Software Developer was asked 5d agoQ1. Can you provide an explanation of your project?
A Software Developer was asked 2mo agoQ2. Why should we choose you?
A Software Developer was asked 2mo agoQ3. What are your hobbies?
TCS Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits