PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Capital One

Solve four algorithmic coding tasks

Last updated: Apr 9, 2026

Quick Overview

This multi-part question evaluates algorithmic problem-solving across frequency counting (equal-value pairs), simulation and in-place grid transformation (match-three gravity), matrix diagonal pattern checking, and interval/range data-structure management, emphasizing correctness under constraints and rigorous time/space complexity reasoning.

  • Medium
  • Capital One
  • Coding & Algorithms
  • Software Engineer

Solve four algorithmic coding tasks

Company: Capital One

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Take-home Project

You will solve four independent coding tasks: 1) Count equal-value pairs in an array: Given an integer array nums of length n, return the number of index pairs (i, j) with 0 ≤ i < j < n and nums[i] = nums[j]. Target time/space: O(n) time using O(n) auxiliary space. Explain the approach and complexity. 2) Simulate a match-three board with gravity: Given an R × C grid board of uppercase letters (colors) or '.' for empty. Repeatedly, in a single round, mark every cell that belongs to any horizontal or vertical run of length ≥ 3 of the same letter (runs can overlap). Remove all marked cells (set to '.'), then apply gravity so that in each column letters fall down and '.' move up. Repeat rounds until the board is stable (no removals). Return the final grid. Constraints: 1 ≤ R, C ≤ 50. Describe the algorithm and its complexity. 3) Check an X-pattern in a square matrix: Given an n × n integer matrix, return true iff every element on the main diagonal and the anti-diagonal is non-zero and every other element is zero; otherwise return false. Constraints: 1 ≤ n ≤ 100. Provide the check and complexity. 4) Process block placement queries on a line: You have N empty positions labeled 1..N. Process Q operations of two types: - Place l r: mark all positions in the inclusive interval [l, r] as occupied (placing on already-occupied cells has no additional effect). - Query k: return the leftmost starting index s such that there exists a contiguous unoccupied segment [s, s+k-1] of length k; if no such segment exists, return -1. Design a data structure to support up to N, Q ≤ 2×10^5 with near O((N + Q) log N) total time. Explain the data structures used and provide the algorithm.

Quick Answer: This multi-part question evaluates algorithmic problem-solving across frequency counting (equal-value pairs), simulation and in-place grid transformation (match-three gravity), matrix diagonal pattern checking, and interval/range data-structure management, emphasizing correctness under constraints and rigorous time/space complexity reasoning.

Related Interview Questions

  • Solve Four Coding Assessment Tasks - Capital One (medium)
  • Write SQL using joins and window functions - Capital One (medium)
  • Review Preprocessing Code and Tests - Capital One (easy)
  • Remove nodes with a given value - Capital One (medium)
  • Solve multiple algorithmic interview questions - Capital One (hard)
Capital One logo
Capital One
Sep 6, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
18
0

You will solve four independent coding tasks:

  1. Count equal-value pairs in an array: Given an integer array nums of length n, return the number of index pairs (i, j) with 0 ≤ i < j < n and nums[i] = nums[j]. Target time/space: O(n) time using O(n) auxiliary space. Explain the approach and complexity.
  2. Simulate a match-three board with gravity: Given an R × C grid board of uppercase letters (colors) or '.' for empty. Repeatedly, in a single round, mark every cell that belongs to any horizontal or vertical run of length ≥ 3 of the same letter (runs can overlap). Remove all marked cells (set to '.'), then apply gravity so that in each column letters fall down and '.' move up. Repeat rounds until the board is stable (no removals). Return the final grid. Constraints: 1 ≤ R, C ≤ 50. Describe the algorithm and its complexity.
  3. Check an X-pattern in a square matrix: Given an n × n integer matrix, return true iff every element on the main diagonal and the anti-diagonal is non-zero and every other element is zero; otherwise return false. Constraints: 1 ≤ n ≤ 100. Provide the check and complexity.
  4. Process block placement queries on a line: You have N empty positions labeled 1..N. Process Q operations of two types:
  • Place l r: mark all positions in the inclusive interval [l, r] as occupied (placing on already-occupied cells has no additional effect).
  • Query k: return the leftmost starting index s such that there exists a contiguous unoccupied segment [s, s+k-1] of length k; if no such segment exists, return -1. Design a data structure to support up to N, Q ≤ 2×10^5 with near O((N + Q) log N) total time. Explain the data structures used and provide the algorithm.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Capital One•More Software Engineer•Capital One Software Engineer•Capital One Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.