This file contains 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 os | |
import random | |
import re | |
import sys | |
import numpy as np | |
def VirginSquare(sq): | |
host = np.zeros(shape=(3,3)) | |
missing = list() | |
index = list() |
This file contains 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
#Solution works only on LeetCode | |
class Solution: | |
def twoSum(self, nums: List[int], target: int) -> List[int]: | |
anums = nums | |
for i in range(len(nums)-1): | |
for j in range(i+1,len(anums)): | |
if nums[i] + anums[j] == target: | |
return[i,j] |
This file contains 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
#Solution works only on LeetCode | |
class Solution: | |
def reverse(self, x: int) -> int: | |
if not x < 0: | |
y = int(str(x)[::-1]) | |
else: | |
x = x * -1 | |
y = int(str(x)[::-1]) * -1 | |
if y <= -2**31 or y >= 2**31 - 1: |
This file contains 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
#This solution works only when executed on LeetCode. For test cases and practice, check my git repo | |
class Solution: | |
def romanToInt(self, s: str) -> int: | |
Guide = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D': 500, 'M':1000} | |
num = prev_char = 0 | |
for char in s[::-1]: | |
if Guide[char] >= prev_char: | |
prev_char = Guide[char] | |
num = num + Guide[char] | |
else: |
This file contains 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
#This solution works only when executed on LeetCode. For test cases and practice, check my git repo | |
class Solution: | |
def isPalindrome(self, x: int) -> bool: | |
rev = '' | |
for char in str(x)[::-1]: | |
rev = rev + char | |
if str(x) == rev: | |
return(True) | |
else: | |
return(False) |
This file contains 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
#This is a test case check. Please check my git repo for the actual solution to go into HackerRank | |
def choco(s,d,m): | |
can = 0 | |
if len(s) > 1: | |
for sq in range(len(s)-m): | |
if sum(s[sq:sq+m]) == d: | |
can += 1 | |
else: | |
if s[0] == d: | |
can = 1 |
This file contains 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 migrate(birds): | |
birds.sort() | |
FFB = my_bird = count = 0 | |
for bird in range(len(birds)-1): | |
if birds[bird] == birds[bird+1]: | |
count += 1 | |
if count > my_bird: | |
my_bird = count | |
FFB = birds[bird] | |
else: |
This file contains 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
# This is a test case, please check my git rrepo for the code that goes on HackerRank | |
def pair(a,num): | |
b = a | |
count = 0 | |
for i in range(len(a)-1): | |
for j in range(i+1,len(b)): | |
if (a[i] + b[j]) % num == 0: | |
count += 1 | |
return count | |
This file contains 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
# Day of the coder from HackerRank | |
def russia(year): | |
days = 256 | |
sams = 0 | |
months = [31,28,31,30,31,30,31,31,30] | |
if 1700 <= year <= 1917: | |
months[8] = months[8] - 13 | |
if (year % 4) == 0: | |
months[1] = months[1] + 1 | |
elif year == 1918: |
This file contains 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
#Can you believe I wrote another solution with just 3 lines of code? Check my Git repo for the actual code! | |
class Palindrome: | |
def text(self, set_of_chars): | |
rev = clean = '' | |
for char in set_of_chars[::-1]: | |
if char.isalnum(): | |
rev = rev + char.lower() | |
for ele in set_of_chars[::1]: |
OlderNewer