Simulate a Deterministic Finite Automaton
Updated
Problem statement
Simulate a deterministic finite automaton and return whether it accepts input.
The automaton has states numbered from 0 through transitions.length - 1. For every state s:
transitions[s][0]is the next state after readinga.transitions[s][1]is the next state after readingb.
Begin at startState and process the characters of input from left to right. Return true if the state reached after the entire string belongs to acceptingStates; otherwise, return false. An empty input performs no transition, so acceptance depends on whether startState is accepting.
Function
acceptsDFA(input: String, transitions: int[][], startState: int, acceptingStates: int[]) → booleanExamples
Example 1
input = "abba"transitions = [[1,0],[1,0]]startState = 0acceptingStates = [1]return = trueThe visited states are 0 -> 1 -> 0 -> 0 -> 1. The final state 1 is accepting.
Example 2
input = "bbb"transitions = [[1,0],[1,0]]startState = 0acceptingStates = [1]return = falseEvery b transition keeps the automaton at state 0, which is not accepting.
Example 3
input = ""transitions = [[0,0]]startState = 0acceptingStates = [0]return = trueThe empty input leaves the automaton at its accepting start state.
Constraints
1 <= transitions.length <= 100000transitions[s].length == 2for every states.- Every transition destination,
startState, and accepting state is between0andtransitions.length - 1. 0 <= input.length <= 100000inputcontains onlyaandb.acceptingStatescontains distinct state numbers.
More Point72 interview questions
- Maximize Array Beauty After DeletionsOA · Seen Aug 2026
- Initial Public OfferingOA · Seen Jul 2026
- Test the HypothesisOA · Seen Jul 2026
- Get Triplet CountOA · Seen Jul 2026
- Internet Service Provider Monthly ReportOA · Seen Jul 2026
- Server SelectionOA · Seen Jul 2026
- Lexicographically Smallest String After Substring OperationOA · Seen May 2026
- Best Time to Buy and Sell Stock IIPHONE SCREEN · Seen Aug 2026
- Find Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Aug 2026
- Generate an Optimal Portfolio Trading ReportPHONE SCREEN · Seen Apr 2026
Similar questions at other companies
- Collect Letters Along a Unique Grid PathApple · OAApple interview questions
- Repair One Movement InstructionOpenAI · OAOpenAI interview questions
- Count Straight-Line Word Occurrences in a GridOptiver · OAOptiver interview questions
- Count Straight-Line Word Occurrences in a GridVisa · OAVisa interview questions
- Flip Rows and Columns, Count ZerosNutanix · OANutanix interview questions
- Hidden ArtifactsIMC Trading · OAIMC Trading interview questions
- Excel Training Data and Model Response AuditMicrosoft · PHONE SCREENMicrosoft interview questions
- BitFont Part 1 - Render a CharacterStripe · ONSITE INTERVIEWStripe interview questions
- Alphabet Board PathZillow · ONSITE INTERVIEWZillow interview questions
- Cyclic Fuel Command SimulationWaymo · ONSITE INTERVIEWWaymo interview questions