Uber Interview - Senior Software Engineer - Nov 2024

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-04-01Added By Anonymous
Source: Link

Company: Uber

Role: Senior Software Engineer

Interview Stage: Phone Screen


Year: 2024


Original Post Content:

You are given a string s, and you have to count the total number of unique substring, where the substring have the same number of frequency of each unique character in that substring. Also the given string can have only digits from '0' to '9'.


Ex 1:


given string s = "1212"

answer is 5 : "1", "2", "12", "21" & "1212".

As "12" have each unique char 1 and 2 have frequency 1 and similarly in "1212" we have unique chars 1 and 2 with each having frequency of 2

Here "121" is not valid substring as the frequency of 1 and 2 are not equal.


Ex 2:


s = "11202"

answer is 8 : "1", "2", "0", "11", "12", "20", "02", "120"

here "2" and "02" will be considered as different string.


I could write code using sliding window with O(N^2) time and O(N^3) space complexity. Interviewer insisting on reducing the space complexity to a lower order.


To figure out the unique string we need to store our max n^2 string and each can be of length n. So the complexity was O(n^3).


Any suggestion to reduce the space complexity and even time if possible.

Comments