Skip to content

Instantly share code, notes, and snippets.

View RP-3's full-sized avatar

Rohan Rogers RP-3

  • San Francisco Bay Area
View GitHub Profile
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
var removeZeroSumSublists = function(head) {
const array = [];
/**
* @param {number} n
* @return {boolean}
*/
var isHappy = function(n) {
const seen = new Set();
const next = (n) => {
let sum = 0;
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
/**
* @param {number[]} A
* @param {number} L
* @param {number} M
* @return {number}
*/
/*
Brute Force: O((n-L)(n-M))
Idea: For each possible window of size L, find
/**
* @param {string[]} queries
* @param {string} pattern
* @return {boolean[]}
*/
// O(n) but massively overcomplicated.
var camelMatch = function(queries, pattern) {
const pCapSegments = capitalSegments(pattern);
/**
* @param {number[]} nums
* @return {boolean}
*/
// O(n)
// Idea: track the lowest and highest number so far.
// If you find a number higher than the highest so
// far, you've found a triplet sequence!
var increasingTriplet = function(nums) {
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
class Solution:
def rotateRight(self, head: ListNode, k: int) -> ListNode:
if not head: return None
# get the length of the list
length, current = 0, head
while current:
length+=1
current = current.next
k%=length
class MinStack:
def __init__(self):
"""
initialize your data structure here.
"""
self.mins = []
self.stack = []
"""
Idea:
- If the question asked us to find the longest line in one cardinal direction
(for example, south) from any point in the grid, we could just cache that
value for every cell. I.e., for every cell, starting from the bottom, draw
the longest line upwards that we can where at each cell the value = 1 + the
value at the cell below it.
- Instead, we're being asked to find the longest lin in ALL cardinal directions
so we can just repeat this process four times--once for each cardinal direction
- Now the kicker: they also want the longest symmetrical line, i.e., the minimum