Back and Forward Navigation for an In-App Browser

Last updated: November 29, 2026

Quick Overview

Design the history for an in-app browser with visit(url), back(steps) and forward(steps). Visiting a new page clears the forward history, and back or forward stop at the ends.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Design the history for an in-app browser with visit(url), back(steps) and forward(steps). Visiting a new page clears the forward history, and back or forward stop at the ends.

Links opened from Facebook and Instagram load in an in-app browser, and this question models its navigation stack. Interviewers want a simple, correct structure with O(1) operations and careful handling of the forward history being discarded.

What the Interviewer Expects
  • Clarify clamping when steps exceed available history
  • Choose an array with a cursor instead of two stacks
  • Make visit O(1) by overwriting instead of truncating
  • Track the last valid forward index
  • Walk through a sequence of calls to prove correctness
Key Topics to Cover
Array
Two pointers
Stack
Data structure design
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you cap history at the last 50 pages?
  • How would you persist history across app restarts?
  • What if each tab has its own history and tabs can be duplicated?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • visit(url) moves to a new page and clears forward history.
  • back(k) and forward(k) move up to k steps and return the current url.
  • Start on a homepage....
High-Level Design

Two stacks work but cost O(k) per move. An array with a cur cursor and a last marker is simpler: back and forward just move the cursor within [0, last]. On visit we advance cur, write the url ...


Submit Your Answer
Markdown supported