Python | Element with largest frequency in list
This is one of the most essential operation that programmer quite often comes in terms with. Be it development or competitive programming, this utility is quite essential to master as it helps to perform many tasks that involve this task to be its subtask. Lets discuss various approaches to achieve this operation. Method #1 : Naive method As the brute force method, we just count all the elements and then just return the element whole count remains the maximum at the end. This is the basic method that one could think of executing when faced with this issue....
read more
Count the number of pairs (i, j) such that either arr[i] is divisible by arr[j] or arr[j] is divisible by arr[i]
Given an array arr[] of N integers, the task is to find the count of unordered index pairs (i, j) such that i != j and 0 <=i < j < N and either arr[i] is divisible by arr[j] or arr[j] is divisible by arr[i]....
read more
Count of subarrays of size K with elements having even frequencies
Given an array arr[] and an integer K, the task is to count subarrays of size K in which every element appears an even number of times in the subarray....
read more
Sum of floor division of all pairs from given array
Given an array arr[] of size N, the task is to find the sum of the floor value of (arr[i] / arr[j]) for all pairs of indices (i, j)....
read more
String with maximum number of unique characters
Given a list of strings Str, find the largest string among all. The largest string is the string with the largest number of unique characters....
read more
Convert string X to an anagram of string Y with minimum replacements
Given two strings X and Y, we need to convert string X into an anagram of string Y with minimum replacements. If we have multiple ways of achieving the target, we go for the lexicographically smaller string where the length of each string...
read more
Length of the largest substring which have character with frequency greater than or equal to half of the substring
Given a string S consisting of characters from ‘a’ to ‘z’. The task is to find the length of the largest substring of S which contains a character whose frequency in the sub-string is greater than or equal to half of the length of the substring.Note: For odd-length substring, to calculate half-length consider integer division. For example, half of 11 is 5....
read more
Check if Binary Array can be made Palindrome by flipping two bits at a time
Given a binary array A[] of size N, the task is to check whether the array can be converted into a palindrome by flipping two bits in each operation....
read more
Program to sort string in descending order
Given a string, sort it in descending order....
read more
Maximize count of unique array elements by incrementing array elements by K
Given an array arr[] consisting of N integers and an integer K, the task is to find the maximum number of unique elements possible by increasing any array element by K only once....
read more
Find the array element having equal count of Prime Numbers on its left and right
Given an array arr[] consisting of N positive integers, the task is to find an index from the array having count of prime numbers present on its left and right are equal....
read more
Largest index for each distinct character in given string with frequency K
Given a string S consisting of lowercase English letters and an integer K, the task is to find, for each distinct character in S, the largest index having this character exactly K times. If no such characters exist, print -1. Print the result in a lexicographical ordering.Note: Consider 0-based indexing in S....
read more