Python - Maximum N repeated Elements Given a List of elements, we need to remove an element if it's occurrence in the list increases more than N. For example,Input : a = [6, 4, 6, 3, 6], N = 1Output : [6, 4, 3]Explanation : The occurrence 2nd onwards of 6 are removed.Input : a = [6, 4, 6, 3, 6], N = 2Output : [6, 4, 6, 3]Explanation :
4 min read
Python - Remove Elements in K distance with N Given a list, remove all elements which are within K distance with N. Input : test_list = [4, 5, 9, 1, 10, 6, 13 ], K = 3, N = 5 Output : [9, 1, 10, 13] Explanation : 4 is removed as 5 - 4 = 1 < 3, hence its within distance. Input : test_list = [1, 10, 6, 13 ], K = 3, N = 5 Output : [1, 10, 13] E
5 min read
Python - Extract Missing Ranges Given list of tuples, start range and end range values, extract the ranges that are missing from the list. Input : test_list = [(7, 2), (15, 19), (38, 50)], strt_val = 5, stop_val = 60 Output : [(5, 7), (2, 60), (2, 15), (19, 60), (19, 38), (50, 60)] Explanation : Missing element ranges starting fro
2 min read
Python - Filter Rows with Range Elements Given a Matrix, filter all the rows which contain all elements in the given number range. Input : test_list = [[3, 2, 4, 5, 10], [3, 2, 5, 19], [2, 5, 10], [2, 3, 4, 5, 6, 7]], i, j = 2, 5 Output : [[3, 2, 4, 5, 10], [2, 3, 4, 5, 6, 7]] Explanation : 2, 3, 4, 5 all are present in above rows. Input :
5 min read
Python - Filter Range Length Tuples We are given a list of tuples where each tuple contains multiple elements, and our task is to filter out tuples whose lengths do not fall within a specified range. For example, if we have a = [(1, 2), (3, 4, 5), (6,), (7, 8, 9, 10)] and the range (2, 3), we should keep only tuples with 2 or 3 elemen
3 min read