FastPrepChoose Your Own Ending
Problems/Choose Your Own Ending

Choose Your Own Ending

WhatNot logoWhatNot● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An internship report names a choose-your-own-ending coding exercise. Our version is about 55% the same as the reported question. Numbered pages, two next-page choices, a starting page, the end rules, a marker result, examples, and limits are our assumptions.

A branching story has pages numbered from 0 to n - 1. The two integers in nextPages[p] describe page p:

  • [-1,-1] means that page p is a terminal ending.
  • Otherwise, the first integer is the next page for choice 0, and the second is the next page for choice 1.

Start at page 0 and consume the supplied choices in order. Stop as soon as a terminal page is reached and return its page number; ignore any choices left over. If all choices are consumed while the current page is not terminal, return -1.

Pages may form cycles and may be visited repeatedly. The finite choice sequence limits how many transitions are performed; do not search for an ending that the supplied choices do not reach.

Function

chooseEnding(nextPages: int[][], choices: int[]) → int

Examples

Example 1

nextPages = [[1,2],[-1,-1],[1,3],[-1,-1]]choices = [1,1]return = 3

Starting at page 0, the two right choices move to page 2 and then terminal page 3.

Example 2

nextPages = [[1,2],[-1,-1],[1,3],[-1,-1]]choices = [1]return = -1

The only choice reaches page 2, which is not terminal. No choices remain.

Example 3

nextPages = [[-1,-1]]choices = [0,1]return = 0

The starting page is already an ending, so the extra choices are ignored.

Constraints

  • 1 <= nextPages.length <= 50.
  • Every row has exactly two values. A row is either [-1,-1] or contains two valid page numbers from 0 to nextPages.length - 1.
  • 0 <= choices.length <= 200, and every choice is 0 or 1.

More WhatNot Phone Screen questions

  • Merge Sorted Squares of Two ArraysPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Adjacent Pair and Run RemovalPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • User Journey Paths from a Log StreamPHONE SCREEN · Seen Nov 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

  • Lazy Filter over a GeneratorSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
  • Array-Backed Set Without Library CollectionsOde with Anthropic · PHONE SCREEN
  • Paginate Retained Conversation HistorySierra · PHONE SCREENSierra interview questions
  • Validate a Chess Bishop, Rook, or Queen MoveGlean · PHONE SCREENGlean interview questions
  • Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
  • Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
  • Bounded IPv4 FilterAmazon · PHONE SCREEN

Interview reports that mention this question

  • Whatnot interviews · February 2026

WhatNot interview experiences

  • Whatnot SWE New Grad
  • Whatnot OA · 2024
  • Whatnot OA · November 2023
  • Whatnot interviews · November 2023
  • Whatnot interviews · February 2024
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public int chooseEnding(int[][] nextPages, int[] choices) {
        // write your code here
    }
}
Checking account…