TypeScript Interview Programs
30 TypeScript programs asked in SDET and automation interviews, ordered from easy to hard. Each one has a worked example, hints and starter code; sign in to see the reference solution.
Easy (12)
- Check a palindrome
Return whether an ASCII string reads identically forwards and backwards; comparison is case-sensitive.
Easy· Two Pointers ·10 min
- Check whether two strings are anagrams
Given exactly two ASCII strings, return whether their case-sensitive character frequencies match.
Easy· Hashing ·10 min
- Compute factorial
Return n factorial for an integer n from 0 through 18.
Easy· Numbers ·10 min
- Find the greatest common divisor
Given exactly two integers, return their nonnegative greatest common divisor, with gcd(0,0) defined as 0.
Easy· Math ·10 min
- Find the missing number from zero to n
The array contains distinct integers from 0 through n with exactly one missing, where n is its length. Return the missing integer.
Easy· Arrays ·10 min
- Find the second distinct largest number
Return the second distinct largest number, or null when fewer than two distinct numbers exist.
Easy· Arrays ·10 min
- Generate the Fibonacci sequence
Return the first n Fibonacci numbers starting with 0 and 1, where 0 <= n <= 50.
Easy· Numbers ·10 min
- Move zeroes to the end
Return all nonzero values in their original order followed by all zeroes.
Easy· Arrays ·10 min
- Reverse a string
Reverse the characters of an ASCII string, retaining spaces and punctuation.
Easy· Strings ·10 min
- Search a sorted array
Given a strictly increasing array and a target, return its zero-based index or -1 when absent.
Easy· Sorting & Searching ·10 min
- Sum the digits of an integer
Return the sum of the decimal digits of the absolute value of an integer.
Easy· Numbers ·10 min
- Test whether a number is prime
Return whether the integer is prime; values below 2 are not prime.
Easy· Math ·10 min
Medium (13)
- Compress consecutive character runs
For each consecutive run of ASCII letters, output its character followed by its decimal count, including counts of one.
Medium· Strings ·25 min
- Find the first non-repeated character
Return the first ASCII character appearing exactly once, or the empty string if none exists.
Medium· Hashing ·25 min
- Find the maximum contiguous subarray sum
Return the largest sum of a nonempty contiguous subarray. The input array has at least one element.
Medium· Dynamic Programming ·25 min
- Find two indices with a target sum
Return indices [i,j] with i < j and values summing to target. Choose the smallest j, then smallest i; return [] if absent.
Medium· Hashing ·25 min
- Flatten a nested numeric array
Flatten a nested array of numbers into a numeric array in left-to-right depth-first order. Empty nested arrays contribute no elements.
Medium· Recursion ·25 min
- Group typed records by category
Group records by category into objects {category,ids}. Preserve first-seen category order and input id order within each group, including duplicate ids.
Medium· Collections ·25 min
- Merge overlapping intervals
Given closed intervals [start,end] with start <= end, merge all overlaps including shared endpoints. Return intervals sorted by start.
Medium· Sorting & Searching ·25 min
- Merge two sorted arrays
Merge two nondecreasing arrays into one nondecreasing array, preserving duplicates.
Medium· Two Pointers ·25 min
- Remove duplicates with a generic helper
Return unique primitive values in first-occurrence order; numeric 1 and string "1" are distinct. Implement a generic helper for strings and numbers.
Medium· Collections ·25 min
- Rotate an array to the right
Rotate values right by nonnegative k positions, with k <= 1000000. An empty array remains empty.
Medium· Arrays ·25 min
- Split an array into typed chunks
Split values into consecutive chunks of positive size (1 to 10000). Only the final chunk may be shorter; use a generic chunk helper.
Medium· Collections ·25 min
- Traverse a matrix in spiral order
Return the clockwise spiral traversal of a rectangular matrix, starting at its top-left cell. Empty matrices are allowed.
Medium· Matrices ·25 min
- Validate balanced brackets
Return whether a string consisting only of parentheses, square brackets, and braces is properly nested.
Medium· Stack & Queue ·25 min
Hard (5)
- Calculate trapped rainwater
Return the units of rainwater trapped between nonnegative bar heights of unit width.
Hard· Two Pointers ·40 min
- Compute the Levenshtein edit distance
Given exactly two ASCII strings of length at most 500, return the minimum insertions, deletions, and substitutions needed to transform the first into the second.
Hard· Dynamic Programming ·40 min
- Find every sliding window maximum
For a nonempty array and 1 <= k <= its length, return the maximum of each consecutive window of length k.
Hard· Stack & Queue ·40 min
- Find the longest substring without repeated characters
Return the maximum length of a contiguous substring with no repeated ASCII characters.
Hard· Sliding Window ·40 min
- Find the median of two sorted arrays
Return the median of two nondecreasing arrays whose combined length is positive. For an even total length, return the mean of the two middle values.
Hard· Sorting & Searching ·40 min
