meesho on campus 3 dsa questions
Company: Meesho
Role: software engineer i
Interview Stage: Coding Round
Location: unknown
Year: unknown
Original Post Content:
1. Question: There is a string s given, and an integer k. You can shift k elements from the start to the back any number of times. The goal is to minimize the sum of (N-i) * pos[s[i]]. The value of N is 1000, so an N^2 solution is acceptable. I implemented this.
2. Question: Given an array of size n. If arr[i] = 2, we need to count the number of numbers of size arr[i] whose sum of digits is 4*k+1, where k can be a positive number. The range of arr[i] is 1e9. I thought it was digit DP, but I couldn't figure it out. I didn't solve it.
3. Question: Given an array of population and a vector<vector<int>> cities representing roads (i.e., there are n cities). They give queries where queries[i][0] = u, queries[i][1] = v, and queries[i][2] = w. There are Q number of queries. We need to return a vector<int> of size Q. We need to find how many cities' populations are at most w on the path from u to v.
I tried to use Union-by-Size and a parent array. I solved it partly. For queries, if parent[u] != parent[v], then the count is 0. Otherwise, if I use BFS, it adds all cities which are of the same component but not part of the path between u and v. So, I thought of DFS: I start with u and go to v. If I find v, then I return 1, and by backtracking, add the cities whose paths are between u and v and whose population is at most w. But I couldn't code this.
I have solved 650+ problems on LeetCode and participated in 25 contests with 1700+ rating. I feel low as I couldn't solve the questions, and the questions' language was confusing. Please guide and tell the answers if possible.