Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Implement a function that simulates a simple finite state machine.

Hard

Problem Statement

Implement a function that simulates a simple finite state machine.

Sample Input

Define states and transitions for a light switch (on/off).

Sample Output

off
on

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
// Simulate a finite state machine function createStateMachine(initialState, transitions) { // Initialize state and define methods to transition states } const lightSwitch = createStateMachine("off", { off: { toggle: "on" }, on: { toggle: "off" } }); console.log(lightSwitch.currentState); // "off" lightSwitch.send("toggle"); console.log(lightSwitch.currentState); // "on"
Log in or sign up to run or submit your code.Log inSign up
Input
Define states and transitions for a light switch (on/off).
Expected Output
off
on