Partial collection of autumn recruitment algorithm questions

Do not provide accessible problem links, nor specify which company.

  1. Write a regular expression to determine whether the first and last letters of two strings are respectively the same, e.g., “aaa” and “aba” are considered matching.
  2. Given an array, find a subarray such that after sorting this subarray the whole array becomes sorted (the subarray length should be minimal).
  3. Evaluate ternary expressions that contain only positive integers, addition, subtraction, multiplication, division, and relational operators, with possible nested ternary expressions.
  4. The K‑th largest element in an array,
  5. LRU
  6. Given an array of length n where each element is in [1, n], find the numbers that appear twice (there may be more than one).
  7. Implement a calculator for addition, subtraction, multiplication, division with parentheses.
  8. Given coordinates of four points, each pair representing a line segment, determine whether the segments intersect.
    9
9 Likes

Expression Evaluation.

Given an expression string that contains only numbers and “±*/()”, compute its value; the expression is guaranteed to be valid.

This really is a classic problem… but I found it truly tiring to write.

Several major companies have tested it. Everyone still needs to practice properly.

3 Likes

python eval seconds

Sure. Write it like this during the interview…

Can it really be written like this (

Obviously cannot.