Find Last Character
Learn this problemProblem statement
You are given an alphanumeric string K. Consider a new string in which S is appended K-1 times.
Now, in this new string, the following operations are performed:-
The above two operations are repeated until one character remains. Your task is to find and return a string representing the last remaining character after performing all the operations.
Note: Here, alphanumeric refers to the string that may contain alphabets (a-z and A-Z), numerals (0-9), and certain special characters such as '$', '#', '&', and '*'
Input Specification:
input1: A string S, representing the alphanumeric string.
input2: An integer value K.
Output Specification:
Return a string representing the last remaining character after performing all the operations mentioned.
Function
findLastCharacter(S: String, K: int) → StringExamples
Example 1
S = "abcd"K = 3return = "b"Example 2
S = "j#k&h"K = 5return = "&"Constraints
1 <= S.length <= 10^51 <= K <= 10^9Scontains letters, digits, or the characters$,#,&, and*.S.length * Kfits in a signed 64-bit integer.
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026