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

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

counting the number of consecutive ocurrences and it's respective quantities on a list (Python)

as I said in the title I want to calculate the consecutive ocurrences and it’s respective quantities on a list. For example: [‘a’,’b’,’a’,’a’] should output [(‘a’,1),(‘b’,1),(‘a’,2)] (or an equivalent format) [‘a’,’a’,’b’,’b’,’b’,’d’] should output [(‘a’, 2), (‘b’, 1),(‘d’,1)] I need this because I’m counting the number of consecutive ocurrences of a timeseries on a specific column… Read More counting the number of consecutive ocurrences and it's respective quantities on a list (Python)