Three problems at the Turbo bar — medium difficulty, each with an obvious O(n²) solution that passes the visible samples and an O(n) or O(n log n) solution that passes the hidden tests. All three are taken from questions reported in Wipro coding rounds; solutions are given in Python, C++, Java and JavaScript and have been executed against the examples shown.
Read a single string S (letters and digits, no spaces). Print the length of the longest substring of S in which no character appears more than once.
Input: abcabcbb
Output: 3
The answer is "abc"; "abca" repeats a.
Input: pwwkew
Output: 3
"wke" — note that "pwke" is a subsequence, not a substring.
Input: bbbbb
Output: 1
- 1 ≤ |S| ≤ 10⁵
- S contains only letters and digits.
- Expected: O(n) time — an O(n²) check of every substring will time out on hidden tests.
The first line contains an integer N. The second line contains N space-separated integers (they may be negative). Print the largest possible sum of a contiguous, non-empty subarray.
Input: 9 -2 1 -3 4 -1 2 1 -5 4
Output: 6
The subarray [4, −1, 2, 1] sums to 6.
Input: 4 -3 -1 -4 -2
Output: -1
All values negative — the best subarray is the single element −1.
- 1 ≤ N ≤ 10⁵
- −10⁴ ≤ A[i] ≤ 10⁴
- Expected: O(n) time, O(1) extra space.
The first line contains an integer N. The second line contains N space-separated integers. For every element, print the first element to its right that is strictly greater than it; print -1 if there is none. Output the N answers on one line, separated by single spaces.
Input: 4 4 5 2 25
Output: 5 25 25 -1
Input: 5 13 7 6 12 10
Output: -1 12 12 -1 -1
13 has nothing greater to its right; 7 and 6 both see 12 next.
- 1 ≤ N ≤ 10⁵
- 1 ≤ A[i] ≤ 10⁹
- Expected: O(n) — the nested-loop O(n²) solution passes only the visible cases.
How Turbo grades differ from Elite
| Submission | Elite outcome | Turbo outcome |
|---|---|---|
| One problem fully solved, second untouched | Often enough with strong aptitude | Rarely shortlisted |
| Both problems, brute force, hidden tests time out | Partial credit, usually clears | Below the bar |
| Both problems, optimal, all tests pass | Clears comfortably | Expected |
Patterns to have ready
- Hash map for pairs and counts — two sum, sock merchant, anagram grouping, duplicate detection.
- Sliding window / two pointers — longest substring without repeats, backspace string compare, sub-array with given sum.
- Monotonic stack — next greater element, valid parentheses, stock span.
- Kadane and prefix sums — maximum subarray, equilibrium index, counting valleys.
- Binary search and merge sort — search in sorted array, first/last occurrence, count inversions.
- Number theory — Euclid's GCD, LCM without overflow, prime sieve, digit palindromes.
Editor discipline
Read input exactly as specified (first line N, second line the array is the most common format), print exactly what is asked with no prompts, use 64-bit integers for sums, and run your code against your own worst case — an all-negative array, a single element, all characters identical — before submitting. The Elite-level warm-ups (sock merchant, counting valleys, backspace compare) are on the Wipro coding questions page; solve those first, then return here.
The business discussion follows up on your test code — be able to state the time and space complexity of what you submitted and how you would improve it. See interview questions.

