Find Smallest Appealing

Problem Overview

  • Find the smallest attractive product code new_code such that new_code ≥ old_code.
  • A code is attractive if its digits repeat every k positions (b[i] = b[i+k]).
  • Input: decimal string old_code of length n and integer k (1 ≤ k < n). Output: decimal string new_code with no leading zeros.
  • Context: generating a more appealing Amazon product code for an online shopping event.
  • From Amazon interviews; a coding interview problem and common interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: