FastPrepLatest New Job
Problems/Latest New Job

Latest New Job

Sphere logoSphere● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionConstraints

Problem statement

Source note: Reported in a Sphere onsite interview. The report gives the query for the latest new job and a discussion of composite indexes. In our schema, creation times are fixed-width UTC text. We also set the tie rules and the examples. The query meaning is about 90% the same as the reported question.

A job table has one row per background job. Return the newest row whose status is new. Write a read-only SQL query or the configured dataframe function.

Input table

ColumnTypeMeaning
job_idintegerUnique job identifier
statustextJob state
created_ontextCreation time as fixed-width UTC text (YYYY-MM-DD HH:mm:ss)

Here, created_on is text, not a timestamp type. Every value is a valid UTC time to the whole second, in the same zero-padded format. So sorting the text in alphabetical order also sorts it by time. Do not convert the values to a local timezone.

Selection rules

  1. Keep only rows whose status is exactly the lowercase text new.
  2. Pick the row with the greatest created_on.
  3. If several matching rows have that same time, pick the one with the smallest job_id.
  4. Return the columns job_id, status and created_on, in that order, with at most one row. If no row matches, return an empty table with those columns.

Optimization follow-up

The interviewer asks how to speed up SELECT * FROM job WHERE status = 'new' ORDER BY created_on DESC LIMIT 1 on a table with about 100 million rows, of which about 20,000 are new. Explain which column order in a composite index helps both the equality filter and the ordering. Do this before you suggest a cache.

Only the rows your query returns are checked. You do not need to create an index, and speed and query plans are not measured. The job_id tie rule above makes the result the same every time.

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.

job

A finite snapshot of job records.

ColumnTypeNullableDescription
job_idPKIntegerNoUnique positive job identifier.
statusTextNoJob state; only the exact lowercase value new is selected.
created_onTextNoA valid UTC creation instant encoded as fixed-width YYYY-MM-DD HH:mm:ss text; lexical order is chronological order.

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
job_idIntegerNoUnique positive job identifier.
statusTextNoJob state; only the exact lowercase value new is selected.
created_onTextNoA valid UTC creation instant encoded as fixed-width YYYY-MM-DD HH:mm:ss text; lexical order is chronological order.

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

Constraints

  • The table contains between 0 and 2,000 rows for this exercise.
  • job_id is unique and is between 1 and 10^9, inclusive.
  • All three columns are non-null.
  • status contains 1 to 20 lowercase ASCII letters or underscores; match only new.
  • created_on is text encoding a valid UTC timestamp as YYYY-MM-DD HH:mm:ss at whole-second precision between 2000-01-01 00:00:00 and 2030-12-31 23:59:59, inclusive.
  • Input rows may appear in any order. Do not mutate the input dataframe.

Similar questions at other companies

  • Second Highest SalaryHartford Financial Services · ONSITE INTERVIEWHartford Financial Services interview questions
  • In-Memory Database QueriesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Weekend Appointments for Consular Services ReschedulingMcKinsey & Company · OAMcKinsey & Company interview questions
  • Benchmarking Tool ReportPalantir · OAPalantir interview questions
  • Prepare Taxi Driver Classification DataBoston Consulting Group · OABoston Consulting Group interview questions
  • Clean the TapeMillennium · OAMillennium interview questions
  • Summarize Customer RecordsAgoda · OAAgoda interview questions
  • Merge IntervalsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Group Transactions by HourAffirm · ONSITE INTERVIEWAffirm interview questions
  • Delete Duplicate Employee RecordsInfosys · ONSITE INTERVIEWInfosys interview questions
See Sphere hiring insights