Skip to content

Instantly share code, notes, and snippets.

from typing import Optional
# optional is used for type hinting when a variable can be of a certain type or None
# i.e. Optional[Item] means the variable can be an Item instance or None, which
# is useful for representing empty slots in the vending machine
# this program can be simplified a lot, but is structured this way to demonstrate
# some object-oriented programming concepts
class Item:
@sellist
sellist / consecutiveNumberSummation.js
Last active March 13, 2023 18:14
Intro to the AND bitwise operator
// The question:
// Some numbers can be made out of a summation of positive consecutive numbers
// Examples:
// 1+2+3 = 6
// 2+3+4 = 9
// 3+4+5+6 = 18
//
// Write a function that takes in an integer and returns a boolean if that number can be made out of a summation of consecutive numbers.
// --------------------------
// First thought was if there was a pattern of numbers that can or cannot be made out of a summation of consecutive numbers
import java.util.Stack;
class ParenthesesValidator {
public String parenthesesValidator(String input) {
Stack<Character> parenStack = new Stack<>();
char[] inputArray = input.toCharArray();
for (char c : inputArray) {
if (c == '(') {
parenStack.push(c);