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?

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

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