PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Capital One

Solve powers, phases, grid pops, and swaps

Last updated: Mar 29, 2026

Quick Overview

This multi-part Coding & Algorithms question evaluates algorithmic problem-solving competencies including number-theoretic checks for powers, modular date arithmetic, grid-based graph traversal and simulation with gravity, string manipulation with combinatorial matching, and analysis of time and space complexity.

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

Solve powers, phases, grid pops, and swaps

Company: Capital One

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Take-home Project

Solve the following four problems: 1) Count powers of k in an array: Given an array of positive integers nums and an integer k >= 1, return how many elements x in nums are exact powers of k (i.e., there exists t >= 0 with x = k^t). Handle the special case k = 1 (only x = 1 qualifies). 2) Compute a moon phase by date: On a planet where moon phases repeat every 8 days (phase indices 0.. 7), you are given the phase index on day 1 of the year and the calendar for that year as a list of month lengths. Given a target date (month, day), compute the phase index on that date by converting the date to a day offset from day 1 and applying modulo 8. Be careful with month-length arithmetic and off-by-one errors. 3) Simulate bubble explosions with gravity: Given an R x C grid of integers representing colors and a threshold T (e.g., T = 3), repeatedly remove any 4-directionally connected component of size >= T consisting of the same color by setting its cells to 0; after each removal, apply gravity within each column so cells fall to the lowest available positions. Continue until no more removals are possible and return the final grid. 4) Count near-equal pairs via at most two swaps: You are given an array of N numeric strings of equal length L (leading zeros allowed). Count unordered pairs (i, j) such that s[i] can be transformed into s[j] using at most two swaps of characters within a single string. Clearly define the transformation rule, state necessary conditions (e.g., matching digit multisets), and design an efficient algorithm with time and space complexity analysis.

Quick Answer: This multi-part Coding & Algorithms question evaluates algorithmic problem-solving competencies including number-theoretic checks for powers, modular date arithmetic, grid-based graph traversal and simulation with gravity, string manipulation with combinatorial matching, and analysis of time and space complexity.

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
7
0

Solve the following four problems:

  1. Count powers of k in an array: Given an array of positive integers nums and an integer k >= 1, return how many elements x in nums are exact powers of k (i.e., there exists t >= 0 with x = k^t). Handle the special case k = 1 (only x = 1 qualifies).
  2. Compute a moon phase by date: On a planet where moon phases repeat every 8 days (phase indices 0.. 7), you are given the phase index on day 1 of the year and the calendar for that year as a list of month lengths. Given a target date (month, day), compute the phase index on that date by converting the date to a day offset from day 1 and applying modulo 8. Be careful with month-length arithmetic and off-by-one errors.
  3. Simulate bubble explosions with gravity: Given an R x C grid of integers representing colors and a threshold T (e.g., T = 3), repeatedly remove any 4-directionally connected component of size >= T consisting of the same color by setting its cells to 0; after each removal, apply gravity within each column so cells fall to the lowest available positions. Continue until no more removals are possible and return the final grid.
  4. Count near-equal pairs via at most two swaps: You are given an array of N numeric strings of equal length L (leading zeros allowed). Count unordered pairs (i, j) such that s[i] can be transformed into s[j] using at most two swaps of characters within a single string. Clearly define the transformation rule, state necessary conditions (e.g., matching digit multisets), and design an efficient algorithm with time and space complexity analysis.

Submit Your Answer

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 8,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.