Turing.com OA Turing Question

turing.com logo
turing.com
September 17, 20259 reads

Summary

I encountered this specific coding problem during my Online Assessment for Turing.com, which challenged me to construct the largest possible number given certain digit repetition constraints.

Full Experience

During the Online Assessment for Turing.com, I was presented with a fascinating algorithmic challenge. The goal was to rearrange the digits of a given number string to form the largest possible new number, but with a crucial constraint: no digit could appear continuously more than 'k' times. This problem required careful thought on how to balance maximizing the number while adhering to the repetition limit across the entire string, especially considering the large input size.

Interview Questions (1)

Q1
Maximize Number with Repetition Constraint
Data Structures & AlgorithmsHard

Given a number string num and an integer k, the task is to find the largest possible number that can be formed by rearranging the digits of num such that no digit appears continuously more than k times.

Example 1:

Input: num = "3391933", k = 3
Output: "9933313"
Explanation: largest possible number is "9933313", as you can see there is no continuous digit which is more than 3 times and largest number.

Example 2:

Input: num = "1121212", k = 2
Output: "221211"
Explanation: largest possible number is "221211", as you can see there is no continuous digit which is more than 2 times.

Constraints:

  • 1 <= k <= num.length <= 10^7
  • num consists of 0 to 9 digits.
Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!