FastPrepFirst Bad Commit
Problems/First Bad Commit

First Bad Commit

WhatNot logoWhatNot● EasyNEW GRADFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Asked in the second technical interview of a late-2024 new grad loop at Whatnot, next to a nearest-points task and some behavioral talk. An experienced candidate had the same pair in a 2022 phone round. In both stories the job is to spot where a history of healthy builds turns broken, and the 2022 one describes that history as labels of good and bad.

Neither story gives size limits, says whether to return a position or a version number, or covers the case with no broken build. Here, the input is the label array, oldest first, and you return a 0-based index, or -1 when nothing is broken.

Our version is about 85% the same as the reported question.

The commits of a project are listed from oldest to newest. A test was run on every commit, and each one is labeled "good" (the test passed) or "bad" (the test failed). A bug got in at some commit and was never fixed, so once a commit is bad, every later commit is bad too.

Given the labels commits, return the 0-based index of the earliest bad commit. If every commit is good, return -1.

Try to read only O(log n) labels, where n is the number of commits.

Function

firstBadCommit(commits: String[]) → int

Examples

Example 1

commits = ["good","good","good","bad","bad","bad"]return = 3

Commits 0 to 2 are good and commit 3 is the first one marked bad.

Example 2

commits = ["good","good"]return = -1

No commit is bad, so the answer is -1.

Example 3

commits = ["bad","bad","bad"]return = 0

The very first commit is already bad.

Example 4

commits = ["good","bad"]return = 1

Only the last commit is bad, so the answer is its index 1.

Constraints

  • 1 <= commits.length <= 104
  • Each commits[i] is "good" or "bad".
  • Every "good" label comes before every "bad" label.

More WhatNot Phone Screen questions

  • Adjacent Pair and Run RemovalPHONE SCREEN · Seen Nov 2026
  • Merge Sorted Squares of Two ArraysPHONE SCREEN · Seen Nov 2026
  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Knight Dialer SequencesPHONE SCREEN · Seen Oct 2026
  • Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
  • Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
  • Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
  • Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
  • Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • First Element Greater Than KMeta · PHONE SCREENMeta interview questions
  • Track New Values in Sorted OrderBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Price at Query TimestampsGoogle · PHONE SCREENGoogle interview questions
  • First Missing Number in a Consecutive ArrayArista Networks · OA · PHONE SCREENArista Networks interview questions
  • Messages in an Inclusive Timestamp RangeAttentive · PHONE SCREEN · ONSITE INTERVIEWAttentive interview questions
  • Target Sum Across Two Sorted ArraysSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Leftmost Binary Search MatchByteDance · PHONE SCREENByteDance interview questions
  • Count Occurrences in a Sorted ArrayAdobe · PHONE SCREEN · ONSITE INTERVIEWAdobe interview questions
  • Find the First Target IndexSuperhuman · PHONE SCREENSuperhuman interview questions
  • First Target IndexGrammarly · PHONE SCREEN

Interview reports that mention this question

  • Whatnot SWE New Grad Second Technical Interview: 8 Experiences

WhatNot interview experiences

  • Whatnot interviews · October 2026
  • Whatnot Experienced SWE Phone Screen Questions: 2 Experiences
  • Whatnot SWE Interview Questions: 6 Experiences
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public int firstBadCommit(String[] commits) {
        // write your code here
    }
}
Checking account…