FastPrepValue at the Kth Node of a Linked List
Problems/Value at the Kth Node of a Linked List

Value at the Kth Node of a Linked List

Capital One logoCapital One● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2018 Capital One software engineer report from a Richmond onsite with two technical interviews names one question, about reaching a given position in a linked list.

It does not say where counting starts or what happens when the list is too short. Here k counts from the head starting at 1, and -1 means the list has fewer than k nodes. Values are never negative, so -1 is clear. The list has up to 1000 nodes. These are our choices.

Our version is about 80% the same as the reported question.

Return the value stored in the k-th node of the linked list that starts at head, counting the head as node 1. If the list has fewer than k nodes, return -1.

Function

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

Examples

Example 1

head = [8,3,11,6]k = 3return = 11
head
83116

Counting from the head, node 1 holds 8, node 2 holds 3 and node 3 holds 11.

Example 2

head = [8,3,11,6]k = 5return = -1
head
83116

The list has only 4 nodes, so there is no 5th node and the answer is -1.

Example 3

head = [0,9]k = 1return = 0
head
09

Counting starts at 1, so the first node is the answer. Its value is 0, a real value rather than a missing node.

Constraints

  • The list has between 0 and 1000 nodes.
  • 0 <= Node.val <= 10^9
  • 1 <= k <= 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
  • Delete a Doubly Linked List Node at a PositionQualys · ONSITE INTERVIEWQualys interview questions
  • Insert After a Linked-List NodeAMD · ONSITE INTERVIEWAMD interview questions
  • Reverse a Singly Linked ListGoogle · ONSITE INTERVIEWGoogle interview questions
  • Process Singly Linked List OperationsSEDEMAC · ONSITE INTERVIEW
  • 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

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 kthElement(ListNode head, int k) {
        // Write your code here.
    }
}
Checking account…