# I'm getting an "Execution Timed Out" error?

I’m trying to improve my algorithm skills. When I run my code, I get an "Execution Timed Out" error. Pseudocode [This is writen in pseudocode] if(number is even) number = number / 2 if(number is odd) number = 3*number + 1 My Code def hotpo(n): calculator = 0 while n >= 1: if n %… Read More I'm getting an "Execution Timed Out" error?

# Maximize the result for given array of values

I have an array of values example: [[1,15], [3,20], [4,30]] each element holds two values, the amount we need to pay at 0th index and items we can collect at 1st index. Also, I have a budget of 4. For this example, I can collect the elements [[1,15], [3,20]] because 1+3 = 4 which matches… Read More Maximize the result for given array of values

The problem i try to solve is this using js : A format for expressing an ordered list of integers is to use a comma separated list of either: -individual integers -or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, ‘-‘. The range… Read More Please Help me solve this problem i have trying to solve Range extraction

The problem i try to solve is this using js : A format for expressing an ordered list of integers is to use a comma separated list of either: -individual integers -or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, ‘-‘. The range… Read More Please Help me solve this problem i have trying to solve Range extraction

# Python – remove punctuation marks at the end and at the beginning of one or more words

I wanted to know how to remove punctuation marks at the end and at the beginning of one or more words. If there are punctuation marks between the word, we don’t remove. for example input: word = "!.test-one,-" output: word = "test-one" >Solution : use strip >>> import string >>> word = "!.test-one,-" >>> word.strip(string.punctuation)… Read More Python – remove punctuation marks at the end and at the beginning of one or more words

# Number of divisors from prime factorization

I am given prime factorization of a number as a map: std::map<int, int> m, where key is a prime number, and value is how many times this prime number occured in product. Example: Prime factorization of 100 is 2 * 2 * 5 *5, so m = 2, and m = 2 My question is… Read More Number of divisors from prime factorization

# How can I optimize for loop?

I want to optimize the time complexity of this code. Now, code has O(n^2) complexity. How can I reduce complexity? input is unsorted array and target, output is true or false. Here`s my code. // pseudo code in js function find(arr, target) { for(let i = 0; i < arr.length; i++){ for(let j = i… Read More How can I optimize for loop?

# Add array to another array with keeping the same amount of indices

I have array A and I am trying to concat it to array B while array B keeps the same amount of indices. for example: const array_A = [1, 2, 3, 4]; const array_B = [0, 0, 0, 0, 0, 0, 0]; the result should look like this const result = [1, 2, 3, 4,… Read More Add array to another array with keeping the same amount of indices

# how to correctly build an expression with comparison operators and brackets?

this not work well: a = [‘123′,’567′,’10’, ‘223’, ’33’] for item in a: if (‘5’ or ‘1’ or ‘2’) in item: print(item) I want to get any item in which there is at least one match with the numbers 1 or 2 or 5 My version is very cumbersome: if ‘5’ in item or ‘1’… Read More how to correctly build an expression with comparison operators and brackets?

# Top K Frequent Words

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. Example 1: Input: words = ["i","love","leetcode","i","love","coding"], k = 2 Output: ["i","love"] Explanation: "i" and "love" are the… Read More Top K Frequent Words