Skip to content

Instantly share code, notes, and snippets.

View FreeRikato's full-sized avatar

Rikato FreeRikato

  • Madurai, Tamil Nadu, India
  • 04:20 (UTC +05:30)
View GitHub Profile
class Solution:
def area(self, length: int, breadth: int) -> int:
return length * breadth
def maxArea(self, height: List[int]) -> int:
i, j = 0, len(height) - 1
max_area = 0
while i < j:
if self.area(min(height[i], height[j]), j - i) > max_area:
max_area = self.area(min(height[i], height[j]), j - i)
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
fixed_point = 0
result = set()
sorted_nums = sorted(nums)
while fixed_point < len(sorted_nums) - 1:
left, right = fixed_point + 1, len(sorted_nums) - 1
while left < right:
three_sum = (
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
left, right = 0, len(numbers) - 1
while left <= right:
two_sum = numbers[left] + numbers[right]
if two_sum == target:
return [left + 1, right + 1]
if two_sum < target:
left += 1
elif two_sum > target:
class Solution:
def isPalindrome(self, s: str) -> bool:
palindrome_string = ""
for character in s.lower():
if character.isalpha() or character.isdigit():
palindrome_string += character
i, j = 0, len(palindrome_string) - 1
while i <= j:
if palindrome_string[i] != palindrome_string[j]:
class Solution:
def longestConsecutive(self, nums: List[int]) -> int:
"""
Using hash set to have unique elements and looping through it to determine elements that are at the start of a sequence. This can be determined if no preious value exist for an element. For such elements, we find if the next values exist and get the sequence length
"""
consecutive_sequence = set(nums)
max_len = 0
for num in consecutive_sequence:
if num - 1 not in consecutive_sequence:
class Solution:
def isValidSudoku(self, board: List[List[str]]) -> bool:
"""
Create a hash set for storing rows, columns and sub box
- Check if the cell value (other than '.') is present in the row, col or box
- Box can be represented with key (r//3, c//3)
- If present then return False
- Else, store the cell values in their respective row, cell and box
"""
US001: User Registration DB
-- US001: Create the User Registration Table and Insert Data
-- Create the table to store user information
-- Attributes are designed with appropriate data types and constraints.
CREATE TABLE Users (
UserID INT PRIMARY KEY AUTO_INCREMENT,
UserName VARCHAR(100) NOT NULL,
Age INT,
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
res = [1] * len(nums)
prefix = 1
for i in range(len(nums)):
res[i] = prefix
prefix *= nums[i]
postfix = 1
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
prefix = [1] * len(nums)
postfix = [1] * len(nums)
counter = 1
for i in range(len(nums)):
counter *= nums[i]
prefix[i] *= counter
class Solution:
"""
@param: strs: a list of strings
@return: encodes a list of strings to a single string.
"""
def encode(self, strs):
# write your code here
encoded_string = ""
for word in strs: