# Capital One Interview Questions  Affirm Interview Questions

## Array Questions Capital One

Question 1. Plus One Leetcode Solution Problem statement   In the problem ” Plus One”  we are given an array where each element in the array represents a digit of a number. The complete array represents a number. The zeroth index represents the MSB of the number.  We can assume that there is no leading zero in ...

Question 2. Count all subsequences having product less than K The problem “Count all subsequences having product less than K” states that you are given an array of integers. Now find the number of subsequences that have a product less than a given input K. Example   a[] = {1, 2, 3, 4, 5} k = 8 Number of subsequences less ...

Question 3. Find any one of the multiple repeating elements in read only array the problem “Find any one of the multiple repeating elements in read only array” states that suppose you are given a read-only array of size (n+1). An array is containing the integers from 1 to n. Your task is to find out any one of the repeated elements in the ...

Question 4. Queries for GCD of all numbers of an array except elements in a given range Problem Statement   The “Queries for GCD of all numbers of an array except elements in a given range” problem states that you will be given an integer array and a q number of queries. Each query contains the number left and right. The problem statement asks to find out the ...

Question 5. Top K Frequent Elements Problem Statement   In top K frequent elements we have given an array nums[], find the k most frequently occurring elements. Examples   nums[] = {1, 1, 1, 2, 2, 3} k = 2 1 2   nums[] = {1} k = 1 1 Naive Approach for Top K Frequent Elements   Build ...

Question 6. Three way partitioning of an array around a given range Problem Statement   You are given an array of integers and a range of lowValue and highValue. The problem “Three way partitioning of an array around a given range” asks to partition the array such that array will be divided into three parts. The partitions of the arrays will be: Elements ...

Question 7. Find a sorted subsequence of size 3 in linear time Problem Statement   The problem “Find a sorted subsequence of size 3 in linear time” states that you have an integer array. The problem statement asks to find out the three numbers in such a way that array[i] < array [k] < array[k], and i < j < k. Example   arr[] ...

Question 8. Sum of minimum and maximum elements of all subarrays of size k Problem Statement   The problem “Sum of minimum and maximum elements of all subarrays of size k” states that you are given an array containing positive and negative integers, find the sum of minimum and maximum elements of all the sub-arrays of size k. Examples   arr[] = {5, 9, 8, 3, ...

Question 9. Move all negative elements to end in order with extra space allowed Problem Statement   “Move all negative elements to end in order with extra space allowed” states that you are given an array containing positive and negative numbers both. The problem statement asks to move all the negative elements in the last of the array. Example   arr[] = { 1,2,-3,-5,2,7,-9,-11 } 1, ...

Question 10. Find the subarray with least average Problem Statement   You have given an integer array and a number k. The problem statement asks to find the subarray with least average, which is to find out the sub-array of k elements, which has the minimum average. Example   arr[] = {12, 34, 20, 30, 24, 45} k = 3 Sub-Array of [0, 2] has a minimum average. Explanation: ...

Question 11. Minimum number of subsets with distinct elements Problem Statement   Suppose you have an array of integers of size n. The problem statement asks to find out the minimum number of subsets with distinct elements, that is subsets that can be formed which contain all the different/distinct elements from the array. Example   arr[] = {2,4,6,2,1,4,2} 3 Explanation: {1, ...

Question 12. Count minimum steps to get the given desired array Problem Statement   Suppose you have an array containing only integer 0 as all of its elements. Consider, you are given an array of length n having all 0s in which we have to convert the 0s to the given required array. We can name the required array as the desiredArr ...

Question 13. Missing Number In Missing Number problem we have given an array of size N containing a number from 0 to N. All the values in the array are unique. We need to find the missing number which is not present in the array and that number lies between 0 to N. Here ...

Question 14. Coin Change Problem Coin Change Problem – Given some coins of different values c1, c2, … , cs (For instance: 1,4,7….). We need an amount n. Use these given coins to form the amount n. You can use a coin as many times as required. Find the total number of ways in which ...

Question 15. Rearrange Positive and Negative Numbers Alternatively in Array Problem Statement   In the “Rearrange Positive and Negative Numbers Alternatively in Array” problem we have given an array a[]. This array contains positive and negative integers. Rearrange the array in such a way that positive and negative are placed alternatively. Here, the number of positive and negative elements need not ...

Question 16. Find the Lost Element From a Duplicated Array Problem Statement   Given two arrays A and B, one array is a duplicate of the other except one element. The one element is missing from either A or B. we need to find the lost element from a duplicated array. Example   5 1 6 4 8 9 6 4 8 ...

Question 17. Rearrange given Array in Maximum Minimum Form Problem Statement   In the “Rearrange given Array in Maximum Minimum Form” problem, we have given a sorted array containing N elements. Rearrange the given sorted array of positive integers, such that alternative elements are ith max and ith min. See below for a better understanding of rearrangement of elements- Array ...

Question 18. Move All the Zeros to the End of the Given Array Problem Statement   In the given array move all the zeros which are present in the array to the end of the array. Here there is always a way exist to insert all the number of zeroes to the end of the array. Example   Input 9 9 17 0 14 0 ...

Question 19. Find Smallest Missing Number in a Sorted Array Problem Statement   In the “Find Smallest Missing Number in a Sorted Array” problem we have given an integer array. Find the smallest missing number in N sized sorted array having unique elements in the range of 0 to M-1, where M>N. Example   Input [0, 1, 2, 3, 4, 6, 7, ...

Question 20. Find the Missing Number Problem Statement   In finding the missing number from an array of 1 to N numbers we have given an array that contains N-1 numbers. One number is missing from an array of numbers from 1 to N. We have to find the missing number. Input Format   First-line containing an integer ...

## String Questions Capital One

Question 21. License Key Formatting Leetcode Solution Problem Statement   In the problem “License Key Formatting”, the input consists of a string of characters, representing a license key. Initially, the string is separated into N + 1 groups(words) by N dashes in between. We are also given an integer K, and the goal is to format the string ...

Question 22. Longest Repeated Subsequence The problem “Longest Repeated Subsequence” states that you are given a string as an input. Find out the longest repeated subsequence, that is the subsequence that exists twice in the string. Example   aeafbdfdg 3 (afd) Approach   The problem asks us to find out the longest repeated subsequence in the string. ...

Question 23. Letter Combinations of a Phone Number In letter combinations of a phone number problem, we have given a string containing numbers from 2 to 9. The problem is to find all the possible combinations that could be represented by that number if every number has some letters assigned to it. The assignment of the number is ...

Question 24. Word Pattern We have all come across word patterns like “ABBA”, “AABB” and so on. We always wonder what this babble could relate to. Today we will try to solve a problem where we try to make use of the babble. A plethora of string problems does not help the case. Given ...

Question 25. Check if a Linked list of Strings form a Palindrome Problem Statement   In the “Check if a Linked list of Strings form a Palindrome” problem we have given a linked list handling string data. Write a program to check whether the data forms a palindrom or not. Example   ba->c->d->ca->b 1 Explanation: In the above example we can see that the ...

## Tree Questions Capital One

Question 26. Convert a normal BST to Balanced BST Problem Statement   Given a Binary Search Tree(BST), write an algorithm to convert the BST to a Balanced Binary Search Tree. A balanced Binary Search tree is nothing but a binary search tree whose difference between the height of left subtree and right subtree is less than or equal to 1. ...

Question 27. Symmetric Tree In Symmetric Tree problem we have given a binary tree, check whether it is a mirror of itself. A tree is said to be a mirror image of itself if there exists an axis of symmetry through a root node that divides the tree into two same halves. Example   Types ...

## Stack Questions Capital One

Question 28. Min Stack Leetcode Solution Problem Statement   Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) — Push element x onto stack. pop() — Removes the element on top of the stack. top() — Get the top element. getMin() — Retrieve the minimum element in the stack. ...

Question 29. Min Stack In min stack problem we have to design a stack to implement the following functions efficiently, push(x) –> Push an element x to the stack pop() –> Removes the item on top of stack top() –> Return the element at top of stack getMin() –> Return the minimum element present ...

## Queue Questions Capital One

Question 30. Sum of minimum and maximum elements of all subarrays of size k Problem Statement   The problem “Sum of minimum and maximum elements of all subarrays of size k” states that you are given an array containing positive and negative integers, find the sum of minimum and maximum elements of all the sub-arrays of size k. Examples   arr[] = {5, 9, 8, 3, ...

## Other Questions Capital One

Question 31. Remove Linked List Elements Leetcode Solution Problem Statement   In this problem, we are given a linked list with its nodes having integer values. We need to delete some nodes from the list which have value equal to val. The problem does not require to be solved in-place but we will discuss one such approach. Example List = ...

Question 32. Palindrome Linked List Leetcode Solution In the problem “Palindrome Linked List”, we have to check whether a given singly integer linked list is a palindrome or not. Example   List = {1 -> 2 -> 3 -> 2 -> 1} true Explanation #1: The list is palindrome as all elements from the start and back are ...

Question 33. Merge Two Sorted Lists Leetcode Solutions Linked lists are quite like arrays in their linear properties. We can merge two sorted arrays to form an overall sorted array. In this problem, we have to merge two sorted linked lists in place to return a new list which contains elements of both lists in a sorted fashion. Example   ...

Question 34. Count Primes Leetcode Solutions In this problem, we are given an integer, N. The goal is to count how numbers less than N, are primes. The integer is constrained to be non-negative. Example   7 3 10 4 Explanation Primes less than 10 are 2, 3, 5 and 7. So, the count is 4. Approach(Brute ...

Question 35. Merge Two Sorted Linked Lists In merge two sorted linked lists we have given head pointer of two linked lists, merge them such that a single linked list is obtained which has nodes with values in sorted order. return the head pointer of the merged linked list. Note: merge the linked list in-place without using ...

Question 36. Merge Two Sorted Lists Leetcode What is merge two sorted lists problem on leetcode?   This is so interesting question asked so many times in compnies like Amazon, Oracle, Microsoft, etc. In this problem(Merge Two Sorted Lists Leetcode), we have given two linked lists. Both linked lists are in increasing order. Merge both linked list in ...

Question 37. LRU Cache Implementation Least Recently Used (LRU) Cache is a type of method which is used to maintain the data such that the time required to use the data is the minimum possible. LRU algorithm used when the cache is full. We remove the least recently used data from the cache memory of ...

Question 38. Sieve of Eratosthenes Sieve of Eratosthenes is an algorithm in which we find out the prime numbers less than N. Here N is an integer value. This is an efficient method to find out the prime numbers to a limit. By using this we can find out the prime numbers till 10000000. Here ... 