Problem of the Day: Remove Duplicate Characters and Digits with Different Rules You are given a string s consisting of lowercase English letters and digits (0–9). You must transform the string in two steps: Characters (a–z): Traverse from left to right. Keep only the first occurrence of each character. Remove all later duplicates. Digits (0–9): Traverse from right to left. Keep only the first digit you encounter (the rightmost occurrence in the original string). Remove earlier duplicates. Return the final transformed string. 1.Input: programming123321 After Step1: progamin123321 Final: progamin321 (keeps the rightmost 1,2,3 — final digits appear as the left-to-right order of their last occurrences) 2. Input: abc11223344 After Step1: abc11223344 Final: abc1234 3. Input: a1b2c1d2e3 After Step1: a1b2c1d2e3 Final: abc1d2e3
Popular posts from this blog
Strings
100 Java String Programming Questions 100 Java String Programming Questions A clean list of 100 string-focused programming questions in Java — arranged Basic → Intermediate → Advanced. Copy this HTML into your Blogger post's HTML editor and tweak the CSS variables at the top to change colors and fonts. A. Basic String Programs (1–40) Write a program to find the length of a string. Write a program to print each character of a string. Write a program to reverse a string. Write a program to check if a string is a palindrome. Write a program to count vowels in a string. Write a program to count consonants in a string. Write a program to count digits in a string. Write a program to count spaces in a string. Write a program to count special characters in a string. Write a program to conver...
Arrays
100 Java Array Programming Questions 100 Java Array Programming Questions A curated list of 100 array-focused programming questions in Java — arranged Basic → Medium → Difficult. Paste this into your Blogger post and edit the colors/font variables in the <style> block. Java • Arrays • Practice A. Basic Array Programs (1–40) Write a program to read and print elements of an array. Write a program to find the length of an array. Write a program to print array elements in reverse order. Write a program to find the sum of array elements. Write a program to find the average of array elements. Write a program to find the maximum element in an array. Write a program to find the minimum element in an array. Write a program to search for an element in an array (linear search). Write a program to count even numbers in an a...





Comments
Post a Comment