FastPrepValue of the Kth Node From the End
Problems/Value of the Kth Node From the End

Value of the Kth Node From the End

Capital One logoCapital One● EasyNEW GRADFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Six Capital One reports from December 2014 to September 2016 ask for a node counted from the tail of a linked list. Three of them come from the Technology Development Program. One also has the candidate build the list first, and one speaks only of a spot found from the end.

In this version the last node is place 1 and the answer is the value stored there. The list is given, so building it is not checked. A negative answer marks a list that is too short. The reports leave this, the numbering and the limits unspecified. Lists have up to 1000 nodes and non-negative values. These are our choices.

Our version is about 90% the same as the reported questions.

head starts a singly linked list. Count its nodes backwards from the tail: the tail is place 1, its predecessor place 2, and so on. Return the value stored in the node at place k.

Return -1 when the list is too short to have a place k.

Function

kthToLast(head: ListNode, k: int) → int

Examples

Example 1

head = [31,7,52,9,18,40]k = 3return = 9
head
3175291840

From the tail the places are 40 (1st), 18 (2nd) and 9 (3rd), so the answer is 9.

Example 2

head = [14,3,8]k = 4return = -1
head
1438

Only three nodes exist, so place 4 counted from the tail is missing and the answer is -1.

Example 3

head = [60,2]k = 2return = 60
head
602

The list has exactly two nodes and k is 2, so the answer is the head, 60.

Constraints

  • The list holds at most 1000 nodes (it may be empty).
  • Each stored value is a whole number from 0 to 10^9.
  • k is a whole number from 1 to 2000.

More Capital One Onsite Interview questions

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Sort ColorsONSITE INTERVIEW · Seen Oct 2026
  • Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
  • Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
  • Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
  • Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
  • Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
  • Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • Detect a Loop in a Linked ListEPAM · ONSITE INTERVIEWEPAM interview questions
  • Merge Two Sorted Linked ListsZS · ONSITE INTERVIEWZS interview questions
  • Middle Node Of A Linked ListNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Build and Check a Palindrome Linked ListOmnissa · ONSITE INTERVIEWOmnissa interview questions
  • Reverse a Singly Linked ListGEP · ONSITE INTERVIEW
  • Merge Two Sorted Linked ListsApple · ONSITE INTERVIEWApple interview questions
  • Reverse a Singly Linked ListMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Reverse Linked ListThe Walt Disney Company · OA · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Detect a Linked-List CycleGoogle · ONSITE INTERVIEWGoogle interview questions
  • Detect a Cycle in a Linked ListPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One hiring insights
Saved
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public int kthToLast(ListNode head, int k) {
        // Write your code here.
    }
}
Checking account…