Skip to content

Instantly share code, notes, and snippets.

View abrarShariar's full-sized avatar
🎯
Focusing

Abrar Shariar abrarShariar

🎯
Focusing
View GitHub Profile
@abrarShariar
abrarShariar / max_sum_k.py
Last active October 12, 2021 18:38
Get the maximum even sum of the K Elements
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
@abrarShariar
abrarShariar / long_sub_str.py
Last active November 8, 2020 12:08
longest substring code
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:
@abrarShariar
abrarShariar / merge_ranges.py
Created September 6, 2020 05:24
merge meetings
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]
@abrarShariar
abrarShariar / get_permutations.py
Created August 26, 2020 11:29
Get permutations of a string
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()
@abrarShariar
abrarShariar / code.js
Created June 24, 2020 06:14
solution
const totalNumberOfPurchase = purchases.reduce((allTotal, product) => {
const sum = product.records.reduce((total, record) => {
return total + record.purchase_num;
}, 0);
return allTotal + sum;
}, 0);
@abrarShariar
abrarShariar / data.js
Created June 24, 2020 06:07
data structure
const purchases = [
{
records: [
{ price: 100 },
{ price: 200 }
]
},
{
records: [
{ price: 400 },
@abrarShariar
abrarShariar / code_1019.py
Created May 15, 2020 01:48
code for finding the next greatest node
# 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 = []
@abrarShariar
abrarShariar / light_morelight.py
Created March 31, 2020 11:37
Light more light
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:
@abrarShariar
abrarShariar / min_swap_list.py
Created March 29, 2020 03:33
Minimum swap final code
def minimumSwaps(arr):
if len(arr) == 1:
return 0
swapCount = 0
position = 1
n = len(arr)
# map position to element
posMap = {}
@abrarShariar
abrarShariar / visited_list
Created March 29, 2020 03:10
Visited List
visited = [False] * (len(arr) + 1)