# Category Archives: Competitive Programming (adsbygoogle = window.adsbygoogle || []).push({});

## Sum of elements in an array having prime frequency

Given an array arr, the task is to find the sum of the elements which have prime frequencies in the array. Note: 1 is neither… Read More »

## Lexicographically Smallest Permutation of length N such that for exactly K indices, a[i] > a[i] + 1

Given two integers N and K, the task is to generate a permutation of N numbers (Every number from 1 to N occurs exactly once)… Read More »

## Minimum elements to be added in a range so that count of elements is divisible by K

Given three integer K, L and R (range [L, R]), the task is to find the minimum number of elements the range must be extended… Read More »

## Check if N can be represented as sum of integers chosen from set {A, B}

Given three integers N, A and B, the task is to find whether N can be represented as sum of A’s and B’s. Examples: Input:… Read More »

## Check if N is divisible by a number which is composed of the digits from the set {A, B}

Given three integers N, A and B, the task is to find whether N is divisible by any number that contains only A and B… Read More »

## Minimum number of increment/decrement operations such that array contains all elements from 1 to N

Given an array of N elements, the task is to convert it into a permutation (Each number from 1 to N occurs exactly once) by… Read More »

## Lexicographically smallest substring with maximum occurrences containing a’s and b’s only

Given a string ( containing characters from ‘0’ to ‘9’) and two digits and . The task is to find the substring in the given… Read More »

## Partiton N into M parts such that difference between Max and Min part is smallest

Given two integers N and M, partiton N into M integers such that the difference between the maximum and minimum integer obtained by the partition… Read More »

## Minimum number of moves required to reach the destination by the king in a chess board

Given four integers sourceX, sourceY, destinationX and destinationY which represent the source and destination coordinates on a chessboard. The task is to find the minimum… Read More »

## Count of pairs in an array whose sum is a perfect square

Given an array of distinct elements, the task is to find the total number of two element pairs from the array whose sum is a… Read More »

## Split N^2 numbers into N groups of equal sum

Given an even number N. The task is to consider numbers from 1 to N2, split them into N groups of the equal sum. Examples:… Read More »

## Sum and Product of Prime Frequencies of Characters in a String

Given a string str containing only lowercase English alphabets, the task is to find the sum and product of all the prime frequencies of the… Read More »

## Sum of the elements from index L to R in an array when arr[i] = i * (-1)^i

Given two integers and and an array arr[] every element of which at index is calculated as arr[i] = i * (-1)i. The task is… Read More »

## Number of leaf nodes in the subtree of every node of an n-ary tree

Given an N-ary tree, print the number of leaf nodes in the subtree of every node. Examples: Input: 1 / \ 2 3 / |… Read More »

## Sort an array according to the increasing count of distinct Prime Factors

Given an array of integers. The task is to sort the given array on the basis increasing count of distinct prime factors. Examples: Input :… Read More »