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
from typing import List, Tuple | |
def bitstrToInt(bs: str) -> int: | |
"""Convert bitstring bs to an integer""" | |
return int(bs, 2) | |
def countBits(d: int) -> int: | |
"""Count the bits in d and return that value""" |
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 TimeInWordsError(Exception): | |
pass | |
def numberToString(d: int) -> str: | |
"""Number to string""" | |
number_look = { | |
1: "one", | |
2: "two", |
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
const MOVES = [[1, 1], [1, 0], [1, -1], [0, 1], [0, -1], [-1, 1], [-1, 0], [-1, -1]] | |
function queensAttack(n: number, k: number, r_q: number, c_q: number, obstacles: number[][]): number { | |
// Write your code here | |
let spaces = 0 | |
const obstacleSet = new Set(obstacles.map(o => `${o[0]},${o[1]}`)) | |
const isvalidpos = (r: number, c: number) => { | |
return r > 0 && r <= n && c > 0 && c <= n |
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
function migratoryBirds(arr: number[]): number { | |
// Write your code here | |
let birdCount: { [key: number]: number} = {} | |
let maxId = 0 | |
let maxIdCount = 0 | |
arr.forEach(bid => { | |
if (birdCount[bid] !== undefined) { | |
birdCount[bid]++ |
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
from typing import Tuple | |
class InvalidGame(Exception): | |
def __init__(self, message): | |
super().__init__(message) | |
class Board: | |
"""N x N chessboard""" |
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
import sys | |
class SinglyLinkedListNode: | |
def __init__(self, node_data): | |
self.data = node_data | |
self.next = None | |
class SinglyLinkedList: |
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
from typing import Tuple | |
class CollatzChase: | |
""" | |
collatz sequence chase | |
""" | |
def __init__(self) -> None: | |
"""initialize""" |
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
from collections import deque | |
from typing import List, Tuple | |
class Board: | |
""" | |
grid hopper | |
starting at (1,1) must hope either down or right by the amount at grid 1,1 | |
can you reach (size, size)? | |
answer yes or now |
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
""" we are the knits of the round table ... """ | |
from typing import Tuple | |
class ChessBoard: | |
""" | |
simple hackerrank style chessboard game with mulitple knights | |
- approach use Sprague Grundy Theorem to determine the winner of a |
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 Board: | |
""" | |
given a coin a position | |
determine if it is a winner or a loser | |
""" | |
N=15 | |
MOVES = [(-2, +1), (-2, -1), (+1, -2), (-1, -2)] | |
def __init__(self): | |
self.grundy = [[-1 for _ in range(self.N + 1)] for _ in range(self.N + 1)] |
NewerOlder