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
class Solution: | |
def maxArea(self, height: List[int]) -> int: | |
maxArea, currArea, l, r = 0,0, 0, len(height)-1 | |
while(l < r and l >= 0 and r <= len(height)-1): | |
currArea = min(height[l],height[r]) * (r-l) | |
if currArea > maxArea: | |
maxArea = currArea # udpate the max area | |
if height[l] < height[r]: # left pointer needs to be incremented |
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 maxSubArray(self, nums: List[int]) -> int: | |
current_sum, max_sum = 0, nums[0] # add first element to max array as len(nums) > 1 (given constaint) | |
for x in nums: | |
current_sum += x | |
if current_sum > max_sum: # update the max sum | |
max_sum = current_sum | |
# reset if sum is negative | |
if current_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
class Solution: | |
def findPeakElement(self, nums: List[int]) -> int: | |
l, r = 0, len(nums)-1 | |
while(l < r): | |
m = (l+r)//2 | |
if nums[m] > nums[m+1]: # peak is at left for sure, so update the r pointer | |
r = m | |
else : # peak is at right for sure, so update l pointer | |
l = m+1 | |
return l |
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
class Solution: | |
def findAnagrams(self, s: str, p: str) -> List[int]: | |
''' | |
1. len(P) >= len(S). if not return [] as there is no anagram | |
2. Take sliding window of len(P) and slide over the S array. Update the frequecy list for each window | |
if both lists are same then add the index to result list.append | |
3. At then end return res list | |
''' | |
res, charP, charS = [], [0]*26, [0]*26 |
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
class Solution: | |
def checkInclusion(self, s1: str, s2: str) -> bool: | |
if len(s2) < len(s1): # edge case | |
return False | |
freq_s1, freq_s2 = [0]*26, [0]*26 | |
# populate freq_s1 list | |
for x in s1: | |
freq_s1[ord(x)-ord('a')] += 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
class Solution: | |
def threeSum(self, nums: List[int]) -> List[List[int]]: | |
# special case | |
if len(nums) <= 2: | |
return [] | |
result = set() # result will contain the unique tuples | |
nums = sorted(nums) # nlog(n) complexity |
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
class Solution: | |
def longestCommonPrefix(self, strs: List[str]) -> str: | |
res = '' # final output | |
if len(strs) == 0: # special case | |
return res | |
min_element = min(strs, key = len) # find the min length word in strs | |
for i in range(len(min_element)): |
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
class Solution: | |
def groupAnagrams(self, strs: List[str]) -> List[List[str]]: | |
if len(strs) == 0: | |
return [] | |
c_dict = {} | |
for word in strs: | |
freq_list = [0]*26 | |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Bootstrap Example</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script> | |
</head> |
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
\documentclass[letterpaper,12pt,titlepage,final]{report} | |
\setlength{\marginparwidth}{0pt} % Please customize the margins as per your need | |
\setlength{\marginparsep}{0pt} % width of space between body text and margin notes | |
\setlength{\evensidemargin}{0.125in} | |
\setlength{\oddsidemargin}{0.125in} | |
\setlength{\textwidth}{6.375in} | |
\raggedbottom | |
\usepackage[utf8]{inputenc} | |
\usepackage{graphicx} | |
\usepackage{subfig} |