Solve classic array, graph, and parsing problems
TeslaSoftware Engineer · HR ScreenLast updated
This multi-part question evaluates algorithmic problem-solving and data-structure competency, covering expression parsing, array and sequence manipulation, sorting-based counting, interval merging, graph traversal/union-find, in-place rearrangement, hashing for set operations, and DAG/topological ordering within the Coding & Algorithms domain.
Implement and analyze solutions to the following independent tasks:
- Expression evaluator: Given a string s of digits, '+', '-', '*', '/', and spaces representing a non-negative integer expression with no parentheses, return its integer value. Division truncates toward zero. Aim for O(n) time using a single pass and O( 1)–O(n) extra space.
- Count triangle triplets: Given an array of positive integers, count triplets (i<j<k) that can form a non-degenerate triangle. Target O(n^
- after sorting.
- Merge ranges: Given a list of closed intervals [l, r], merge all intervals that overlap or touch and return the merged, sorted list.
- Count land clusters: Given an m×n grid of '1' (land) and '0' (water), count the number of 4-directionally connected land clusters. Use DFS, BFS, or Union-Find.
- Smallest missing positive: Given an unsorted integer array, return the smallest missing positive integer in O(n) time and O(
- extra space by rearranging in place.
- Maximum subarray sum: Given an integer array, return the maximum possible sum of a non-empty contiguous subarray. Also return the subarray boundaries if asked.
- Single-transaction stock profit: Given daily prices, compute the maximum profit from one buy and one sell (buy before sell). Return 0 if no profit is possible.
- Longest consecutive run: Given an unsorted array of integers, return the length of the longest sequence of consecutive integers. Achieve average O(n) time using hashing.
- Course completion feasibility: Given numCourses and prerequisite pairs (a, b) meaning b must precede a, determine whether all courses can be finished. If feasible, return any valid ordering. Handle up to 1e5 nodes and edges efficiently.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.