Minimum Number of Pushes to Type Word 2 Problem

Problem Telephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with ["a","b","c"], we need to push the key one time to type "a", two times to type "b", and three times to type "c" . It is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word. ...

Sort Array by Increasing Frequency Problem

Problem Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order. Return the sorted array. Examples Example 1: Input: nums = [1,1,2,2,2,3] Output: [3,1,1,2,2,2] Explanation: '3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3. ...

Find element which appears maximum number of times in the ranged array

Problem Given an array of integers occurring between range[0, n) where n is length of the array, write a algorithm to find the element which appears maximum number of times in the array. Examples Example 1: int [] nums = {4, 1, 5, 2, 1, 5, 9, 8, 6, 5, 3, 2, 4, 7}; n = 14 Output: Element repeating maximum no of times: 5, maximum count: 3 ...

Find most frequent element in the array

Problem Given an array of integers, write a algorithm to find the element which appears maximum number of times in the array. Examples Example 1: int [] arrA = {4, 1, 5, 2, 1, 5, 9, 8, 6, 5, 3, 2, 4, 7}; Output: Element repeating maximum no of times: 5, maximum count: 3 Similar Problem Find the element which appears maximum number of times in the ranged array0, n) ...

Word Frequency from File

Word Frequency From File Problem Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity sake, you may assume: words.txt contains only lowercase characters and space ' ' characters. Each word must consist of lowercase characters only. Words are separated by one or more whitespace characters. Examples Example: Assume that words.txt has the following content: ...

Find frequency of a word in a book

Problem Design a method to find the frequency of occurrences of any given word in a book. Examples Example 1: Input: BookFrequency(String text) text = the day is sunny the the the sunny is is Input: getFrequency("the") Output: 4 Input: getFrequency("is") Output: 3 ...

Top K Frequent Words Problem

Problem Given a document (or stream) of words. Find the top k most frequent words in the document (or stream). OR Given an array of strings words and an integer k, return the k most frequent strings. Return the answer sorted by the frequency from highest to lowest. Sort the words with the same frequency by their lexicographical order. Examples Example 1: Input: words = ["i","love","leetcode","i","love","coding"], k = 2 Output: ["i","love"] Explanation: "i" and "love" are the two most frequent words. Note that "i" comes before "love" due to a lower alphabetical order. ...

Frequency of the Most Frequent Element

Problem The frequency of an element is the number of times it occurs in an array. You are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1. Return the maximum possible frequency of an element after performing at most k operations. Examples Example 1: Input: nums = [1,2,4], k = 5 Output: 3 Explanation: Increment the first element three times and the second element two times to make nums = [4,4,4]. 4 has a frequency of 3. ...

Count frequency of target element in sorted array

Problem Given a sorted array of integers and a target element. Find the number of occurrences of the target in the array. You must write an algorithm with O(log n) runtime complexity. Examples Example 1: Input: nums = [1, 1, 2, 2, 2, 2, 3], target = 2 Output: 4 Explanation: 2 appears four times in the array ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy