Quick Overview

This question evaluates proficiency with linked list manipulation and string sequence comparison, focusing on data structure traversal, character-level comparison, and attention to edge cases. It is commonly asked in the Coding & Algorithms domain to assess practical implementation skills, correctness, and efficiency rather than purely conceptual understanding.

Compare two string linked lists

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

##### Question Given two singly linked lists where each node stores one character as a string, determine whether the sequences of characters represented by the two lists are identical. Return true if they match exactly, otherwise false.

Overview: This question evaluates proficiency with linked list manipulation and string sequence comparison, focusing on data structure traversal, character-level comparison, and attention to edge cases. It is commonly asked in the Coding & Algorithms domain to assess practical implementation skills, correctness, and efficiency rather than purely conceptual understanding.

You are given two singly linked lists represented as arrays of node values in order. Each node stores exactly one character (a string of length 1). Determine whether the sequences of characters represented by the two lists are identical. Return True if they match exactly (same length and same characters in the same order), otherwise return False.

Constraints

  • 0 <= len(list1), len(list2) <= 100000
  • Each element in list1 and list2 is a string of length 1
  • Characters are case-sensitive
  • Aim for O(n) time and O(1) extra space

Hints

  1. Traverse both sequences in lockstep and compare characters one by one.
  2. If one sequence ends before the other, they are not identical.
  3. An early length check (when using arrays) can short-circuit obvious mismatches.

Compare Two String Linked Lists

mediumMetaSoftware EngineerLinked List

You are given two singly linked lists represented as arrays of node values in order. Each node stores exactly one character (a string of length 1). Determine whether the sequences of characters represented by the two lists are identical. Return True if they match exactly (same length and same characters in the same order), otherwise return False.

Examples

Example 1
Input
list1 = ['h','e','l','l','o'], list2 = ['h','e','l','l','o']
Output
True
Notes
Both lists represent the same sequence 'hello'.
Example 2
Input
list1 = ['a','b','c'], list2 = ['a','B','c']
Output
False
Notes
Mismatch at index 1: 'b' != 'B'.

Constraints

  • •0 <= len(list1), len(list2) <= 100000
  • •Each element in list1 and list2 is a string of length 1
  • •Characters are case-sensitive
  • •Aim for O(n) time and O(1) extra space

Comments (0)

No comments yet. Be the first to comment!

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Sample input
{"list1":["a","b","c"],"list2":["a","b","c"]}
Language
Case 1
Input
{
  "list1": [
    "a",
    "b",
    "c"
  ],
  "list2": [
    "a",
    "b",
    "c"
  ]
}
Expected
true
Case 2
Input
{
  "list1": [
    "a",
    "b"
  ],
  "list2": [
    "a",
    "B"
  ]
}
Expected
false

Browse More Questions

Show the approach

Approach

Since each node holds a single character and the lists are represented as arrays of values in order, compare corresponding elements in both sequences. If lengths differ or any pair of characters differs, return False; otherwise return True. This avoids building intermediate strings and uses constant extra space.

Time complexity:
O(n)
Space complexity:
O(1)