Friendship String

Problem Overview

  • Compute the lexicographically smallest string from a digit string by repeatedly removing digit d and inserting min(d+1,9) anywhere.
  • Input: t test cases; each has digit string s (leading zeros allowed). Output: smallest achievable string per test.
  • Constraints: 1<=t<=1e4; 1<=|s|<=2e5; sum |s|<=2e5.
  • Context: friendship game focusing on string manipulation and lexicographic order.
  • Source: Rubrik 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: