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)

  1. Check a palindrome

    Return whether an ASCII string reads identically forwards and backwards; comparison is case-sensitive.

    Easy· Two Pointers ·10 min

  2. Check whether two strings are anagrams

    Given exactly two ASCII strings, return whether their case-sensitive character frequencies match.

    Easy· Hashing ·10 min

  3. Compute factorial

    Return n factorial for an integer n from 0 through 18.

    Easy· Numbers ·10 min

  4. 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

  5. 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

  6. 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

  7. Generate the Fibonacci sequence

    Return the first n Fibonacci numbers starting with 0 and 1, where 0 <= n <= 50.

    Easy· Numbers ·10 min

  8. Move zeroes to the end

    Return all nonzero values in their original order followed by all zeroes.

    Easy· Arrays ·10 min

  9. Reverse a string

    Reverse the characters of an ASCII string, retaining spaces and punctuation.

    Easy· Strings ·10 min

  10. 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

  11. Sum the digits of an integer

    Return the sum of the decimal digits of the absolute value of an integer.

    Easy· Numbers ·10 min

  12. Test whether a number is prime

    Return whether the integer is prime; values below 2 are not prime.

    Easy· Math ·10 min

Medium (13)

  1. 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

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. Merge two sorted arrays

    Merge two nondecreasing arrays into one nondecreasing array, preserving duplicates.

    Medium· Two Pointers ·25 min

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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)

  1. Calculate trapped rainwater

    Return the units of rainwater trapped between nonnegative bar heights of unit width.

    Hard· Two Pointers ·40 min

  2. 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

  3. 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

  4. 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

  5. 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