This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_max_even_sum (input_arr, k): | |
if k > len(input_arr) or len(input_arr) == 0: | |
return -1 | |
even_arr = [] | |
odd_arr = [] | |
# sort the arr | |
input_arr.sort(reverse = True) | |
# separate out the even and odd arr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def length_of_longest_substring(str1, k): | |
window_start, max_length, max_repeat_letter_count = 0, 0, 0 | |
frequency_map = {} | |
# Try to extend the range [window_start, window_end] | |
for window_end in range(len(str1)): | |
right_char = str1[window_end] | |
if right_char not in frequency_map: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge_ranges(meetings): | |
if len(meetings) == 0: | |
return meetings | |
meetings.sort(key=lambda x: x[0]) | |
merged_list = [(meetings[0])] | |
for current_start_time, current_end_time in meetings[1:]: | |
# check if the current start time is less than the end time of the latest end time in the merged list | |
last_merged_start, last_merged_end = merged_list[-1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_permutations(input_str): | |
if len(input_str) <= 1: | |
return set([input_str]) | |
all_chars_except_last = input_str[:-1] | |
last_char = input_str[-1:] | |
permutations_of_all_chars_except_last = get_permutations(all_chars_except_last) | |
permutations = set() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const totalNumberOfPurchase = purchases.reduce((allTotal, product) => { | |
const sum = product.records.reduce((total, record) => { | |
return total + record.purchase_num; | |
}, 0); | |
return allTotal + sum; | |
}, 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const purchases = [ | |
{ | |
records: [ | |
{ price: 100 }, | |
{ price: 200 } | |
] | |
}, | |
{ | |
records: [ | |
{ price: 400 }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for singly-linked list. | |
class ListNode: | |
def __init__(self, val=0, next=None): | |
self.val = val | |
self.next = next | |
class Solution: | |
def nextLargerNodes(self, head: ListNode) -> List[int]: | |
if head == None: | |
return | |
input_list = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def isPerfectSquare(x): | |
sr = math.sqrt(x) | |
return ((sr - math.floor(sr) - 0) == 0) | |
def main(): | |
while True: | |
inp = int(input()) | |
if inp == 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def minimumSwaps(arr): | |
if len(arr) == 1: | |
return 0 | |
swapCount = 0 | |
position = 1 | |
n = len(arr) | |
# map position to element | |
posMap = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
visited = [False] * (len(arr) + 1) |
NewerOlder