293-Flip-Game

Fri 14 November 2025

https://leetcode.com/problems/flip-game

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def generatePossibleNextMoves(self, currentState: str) -> List[str]:
    return [currentState[:i] + '--' + currentState[i + 2:]
            for i, (a, b) in enumerate(zip(currentState, currentState[1:]))
            if a == '+' and b == '+']
new Solution …

Category: leetcode

Read More

294-Flip-Game-Ii

Fri 14 November 2025

https://leetcode.com/problems/flip-game-ii

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  @functools.lru_cache(None)
  def canWin(self, currentState: str) -> bool:
    # If any of currentState[i:i + 2] == "++" and your friend can't win after
    # Changing currentState[i:i + 2] to …

Category: leetcode

Read More

296-Best-Meeting-Point

Fri 14 November 2025

https://leetcode.com/problems/best-meeting-point

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def minTotalDistance(self, grid: List[List[int]]) -> int:
    m = len(grid)
    n = len(grid[0])
    # I indices s.t. grid[i][j] == 1
    I = [i for i in range …

Category: leetcode

Read More

298-Binary-Tree-Longest-Consecutive-Sequence

Fri 14 November 2025

https://leetcode.com/problems/binary-tree-longest-consecutive-sequence

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def longestConsecutive(self, root: Optional[TreeNode]) -> int:
    if not root:
      return 0

    def dfs(root: Optional[TreeNode], target: int, length: int, maxLength: int) -> int:
      if not root:
        return maxLength …

Category: leetcode

Read More

299-Bulls-And-Cows

Fri 14 November 2025

https://leetcode.com/problems/bulls-and-cows

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def getHint(self, secret: str, guess: str) -> str:
    bulls = sum(map(operator.eq, secret, guess))
    bovine = sum(min(secret.count(x), guess.count(x)) for x in set(guess …

Category: leetcode

Read More

3-Bayesian-Optimization-1

Fri 14 November 2025

import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml312-2024; pyv: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:27:36) [GCC 11.2.0]'
# !pip install optuna
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.metrics …

Category: hyperparam-tuning

Read More

3-Longest-Substring-Without-Repeating-Characters

Fri 14 November 2025

https://leetcode.com/problems/longest-substring-without-repeating-characters

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def lengthOfLongestSubstring(self, s: str) -> int:
    ans = 0
    count = Counter()

    l = 0
    for r, c in enumerate(s):
      count[c] += 1
      while count[c] > 1:
        count[s[l]] -= 1 …

Category: leetcode

Read More

3-Longest-Substring-Without-Repeating-Chars

Fri 14 November 2025
# https://leetcode.com/problems/longest-substring-without-repeating-characters/
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml311; pyv: 3.11.10 (main, Oct  3 2024, 07:29:13) [GCC 11.2.0]'
print(pyu.ps2("scipy"))
scipy==1.14.1

from collections import Counter

class Solution:
  def lengthOfLongestSubstring(self, s: str) -> int:
    ans …

Category: leetcode

Read More

3-Plotly

Fri 14 November 2025
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml312-2024; pyv: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:27:36) [GCC 11.2.0]'


!pip show plotly | grep "Version:"
Version: 5.24.1
import plotly.express as px

fig = px.scatter(x=[1, 2, 3 …

Category: plot-compare

Read More

30-Fisher-Transform

Fri 14 November 2025
# Created: 20250104
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml312-2024; pyv: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:27:36) [GCC 11.2.0]'
print(pyu.ps2("yfinance pandas matplotlib"))
yfinance==0.2.51
pandas==2.2.3
matplotlib==3.9.3
import …

Category: stockmarket

Read More
Page 28 of 146

« Prev Next »