FastPrepSecond and Third Distinct Order Values
Problems/Second and Third Distinct Order Values

Second and Third Distinct Order Values

Morgan Stanley logoMorgan Stanley● EasyINTERNPHONE SCREEN

Updated Jul 2024

QuestionConstraints

Problem statement

Source note: The reported value-selection task matches about 75%. The original schemas, tie treatment and missing-rank output were not given;this exercise uses distinct values and NULL for an unavailable rank.

Find the second-lowest and third-lowest order values.

For this exercise, assume orders(order_id, order_value) contains valid nonnegative integer values. Rank distinct values in ascending order;duplicate orders do not consume a rank.

Return exactly one row with columns second_lowest and third_lowest. Return NULL in a column when that distinct rank does not exist. The table may be empty. Inputs must remain unchanged.

Table schema

MySQLPostgreSQLPandas

Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.

orders

ColumnTypeNullableDescription
order_idPKIntegerNo—
order_valueIntegerNo—

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
second_lowestIntegerYes—
third_lowestIntegerYes—

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • Each input table contains from 0 through 1000 rows.
  • Identifiers are positive integers at most 1000000. Every declared primary-key and foreign-key constraint holds.
  • All value and salary columns are nonnegative integers at most 1000000000. Strings are nonempty and have at most 100 characters.
  • Inputs are valid and must not be mutated.

More Morgan Stanley interview questions

  • Unique Grid PathsPHONE SCREEN · Seen Oct 2026
  • Reverse an IntegerPHONE SCREEN · Seen Jul 2024
  • Binary Tree Preorder TraversalPHONE SCREEN · Seen Jan 2024
  • Find a Target-Sum SubarrayPHONE SCREEN · Seen Jan 2024
  • Two SumPHONE SCREEN · Seen Jan 2024
  • Generate Strings of Length at Least ThreeONSITE INTERVIEW · Seen Sep 2026
  • Three-Resource 0/1 KnapsackOA · Seen Sep 2026
  • Maximum Concurrent ProcessesOA · ONSITE INTERVIEW · Seen Sep 2026
  • Kth Largest Array ElementONSITE INTERVIEW · Seen Jul 2026
  • Maximum Total of Nonadjacent RatingsOA · Seen Jul 2026

Similar questions at other companies

  • Second Highest SalaryPaytm · PHONE SCREENPaytm interview questions
  • Employees Who Earn More Than Their ManagersNykaa · PHONE SCREENNykaa interview questions
  • Employees Who Joined More Than a Week AgoNewgen Software · PHONE SCREEN
  • Departments Without EmployeesDell Technologies · PHONE SCREENDell Technologies interview questions
  • Second-Highest Distinct SalaryChubb · PHONE SCREENChubb interview questions
  • Swap Two Gender ValuesInfosys · PHONE SCREENInfosys interview questions
  • Find Rows Common to Two TablesSalesforce · PHONE SCREENSalesforce interview questions
  • Count Records Present in A but Not BCapital One · PHONE SCREENCapital One interview questions
  • Customer Order Count Distribution by CountryApple · PHONE SCREENApple interview questions
  • Employees Earning More Than Their ManagerMygate · PHONE SCREENMygate interview questions

Interview reports that mention this question

  • Morgan Stanley Intern Tech Rounds: 5 Experiences (Part 2 of 5)

Morgan Stanley interview experiences

  • Morgan Stanley Apprenticeship and Tech Interviews: 6 Experiences
  • Morgan Stanley New Grad Technology Analyst: 2 Experiences
  • Morgan Stanley Intern Oldest Loops: 5 Experiences (Part 5 of 5)
  • Morgan Stanley Intern OOP Loops: 5 Experiences (Part 4 of 5)
  • Morgan Stanley Intern Earlier Loops: 5 Experiences (Part 3 of 5)
All Morgan Stanley interview questionsSee Morgan Stanley hiring insights