Skip to content

Instantly share code, notes, and snippets.

View oriItzh's full-sized avatar

Ori Itzhaki oriItzh

  • Independent
View GitHub Profile
class Solution:
def find132pattern(self, nums: List[int]) -> bool:
if len(nums) < 3:
return False
stack = []
min_array = [-1] * len(nums)
min_array[0] = nums[0]
for i in range(1, len(nums)):
min_array[i] = min(min_array[i - 1], nums[i])
class Solution:
def lastRemaining(self, n: int) -> int:
def helper(n, ste=True):
if n == 1:
return n
return 2 * helper(n // 2, not ste) - (0 if ste or n & 1 else 1)
return helper(n, True)
@oriItzh
oriItzh / longest_inc_subseq.py
Created August 20, 2025 15:55
Longest Increasing Subsequence
def lengthOfLIS(self, nums: List[int]) -> int:
dp = [1] * len(nums)
for i in range(1, len(nums)):
longest = 0
for j in range(i):
if nums[j] < nums[i]:
longest = max(longest, dp[j])
dp[i] = longest + 1
return max(dp)
def flip_pairs(num):
if num < 0:
return -flip_pairs(-num)
if num < 10:
return num
last_two = num % 100
ones, tens = last_two % 10, last_two // 10
return 100 * flip_pairs(num // 100) + 10 * ones + tens
class Solution:
def singleNumber(self, nums: List[int]) -> int:
pos_res = neg_res = 0
for bit in range(32):
pos_cnt = neg_cnt = 0
for num in nums:
if num > 0 and (1 << bit) & num:
pos_cnt += 1
if num < 0 and (1 << bit) & -num: