Linked List Palindrome in Constant Space
Updated
Problem statement
Given the head of a singly linked list, return true if its values read the same forwards and backwards. Otherwise, return false.
Use O(1) extra space.
For this exercise, each node has an integer val and a next pointer. The empty list is a palindrome. You may change next pointers; restoring the original list is optional. The examples display the node values as an array in traversal order.
Function
isPalindrome(head: ListNode) → booleanExamples
Example 1
head = [1,2,2,1]return = trueThe first and last values are 1, and the two inner values are 2.
Example 2
head = [1,2,3,2,1]return = trueThe values on both sides of the middle 3 match in reverse order.
Example 3
head = [1,2,3]return = falseThe first value 1 differs from the last value 3.
Example 4
head = []return = trueThe empty list has no mismatched pair, so it is a palindrome.
Constraints
- For this exercise, assume the list contains
0to500nodes. - For this exercise, assume
-10^9 <= node.val <= 10^9. - The input is an acyclic singly linked list.
More NVIDIA Phone Screen questions
- Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
- Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
- Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
- Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
- Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
- Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
- Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
- Merge Multiple Sorted StreamsPHONE SCREEN · Seen Aug 2026
- LRU Key-Value Cache OperationsPHONE SCREEN · Seen Aug 2026
- Transformer KV Cache OperationsPHONE SCREEN · Seen Aug 2026
Similar questions at other companies
- Middle of a Linked ListCisco · PHONE SCREENCisco interview questions
- Merge Two Sorted ListsIBM · PHONE SCREENIBM interview questions
- Count Nodes in a ChainApple · PHONE SCREENApple interview questions
- Detect a Cycle in a Linked ListSalesforce · PHONE SCREENSalesforce interview questions
- Find the Intersection Node of Two Linked ListsVisa · PHONE SCREENVisa interview questions
- Reverse a Linked ListMygate · PHONE SCREENMygate interview questions
- Find the Intersection Node of Two Linked ListsLinkedIn · PHONE SCREENLinkedIn interview questions
- First Node Two Linked Lists ShareAdobe · PHONE SCREENAdobe interview questions
- Reverse a Singly Linked ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Merge Two Sorted Linked ListsExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions