This is a verified interview question from Aveva. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Largest Number After Removing Zeros" covers key patterns like Strings.
"You are given a string named *digits* made of digits '0' and/or '2'. It represents a positive integer. Remove zero or more digits from it, so that each remaining digit occurs an even number of times and the value of the resulting integer is as large as possible. Write a function: ```java class Solution { public String solution(String digits); } ``` that, given a string named *digits* of length N, representing the integer, returns a string representing the largest obtainable integer after performing the removals. ### Examples: 1. Given *digits* = "121212", the function should return "2121". 2. Given *digits* = "2121122", the function should return "221122". 3. Given *digits* = "1111", the function should return "1111". Write an efficient algorithm for the following assumptions: - N is an integer within the range [1..200,000]. - string *digits* is made only of the characters '1' and/or '2'."
Join thousands of developers practicing for Aveva.