Skip to content

Instantly share code, notes, and snippets.

View mlivingston40's full-sized avatar

Matt Livingston mlivingston40

  • Austin, Texas
View GitHub Profile
@mlivingston40
mlivingston40 / twoSum.scala
Last active April 29, 2024 20:10
two sum scala
//import org.json4s.DefaultFormats.++
//import org.json4s.JsonDSL.int2jvalue
object Solution extends App {
def twoSum(nums: Array[Int], target: Int): Option[Array[Int]] = {
var leftIndex: Int = 0
while (leftIndex < nums.length -1) {
println("*****")
@mlivingston40
mlivingston40 / students_exams_all_subjects.sql
Created March 30, 2024 17:11
find all exams by student by subjects
-- Write your PostgreSQL query statement below
select
s.student_id,
s.student_name,
j.subject_name,
sum(case when e.subject_name is null then 0 else 1 end) as attended_exams
from
Students s
Cross join Subjects j
left join Examinations e
@mlivingston40
mlivingston40 / avg_machine_process_time.sql
Last active March 29, 2024 17:54
find the average processing time by machine for all processes
-- Write your PostgreSQL query statement below
/*
Lets first do a table scan to get every process_id's time delta
*/
with process_time_delta as (
Select
machine_id,
process_id,
activity_type,
timestamp,
@mlivingston40
mlivingston40 / rising_temp.sql
Last active March 29, 2024 17:11
Write a solution to find all dates' Id with higher temperatures compared to its previous dates (yesterday).
-- Write your PostgreSQL query statement below
select
id as Id
from
(
select
id,
recordDate,
temperature,
LAG(temperature, 1) OVER (
@mlivingston40
mlivingston40 / most_area.py
Last active March 28, 2024 17:00
Container with most water
class Solution:
def __init__(self):
self.max_area = 0
def getLength(self, index_left, index_right) -> int:
return index_right - index_left
def maxArea(self, height: List[int]) -> int:
class Solution:
def __init__(self):
self.numeric_set = [str(i) for i in range(10)]
self.allowed_set = self.numeric_set
self.allowed_set.append("-")
@mlivingston40
mlivingston40 / battleship.py
Created March 7, 2024 20:54
For the game battleship, count the unique ships on the board for a dynamically sized board
"""
`X` means part of a ship is here
`.` means it is an empty spot
"""
board = [
["X", ".", "X", ".", "X", "X"],
["X", ".", ".", ".", ".", "."],
["X", ".", "X", ".", "X", "."]
]
@mlivingston40
mlivingston40 / longestPalindrome.py
Last active March 5, 2024 20:46
Given a string s, return the longest palindromic substring in s.
def is_Same(char_one: str, char_two: str) -> bool:
return char_one == char_two
class Solution:
def __init__(self):
#todo: could initialize some class vars like s_chars, s_pointer, s_pal_longest
pass
@mlivingston40
mlivingston40 / findMedianSortedArrays.py
Created March 4, 2024 17:34
Find the median value of two merged arrays
class Solution:
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
# first merge the arrays
merged = nums1 + nums2
# sort it inplace
merged.sort()
#todo: now we need to find median
# find the length
merged_len = len(merged)
@mlivingston40
mlivingston40 / merge_k_sorted_lists.py
Created March 1, 2024 18:47
Merge k sorted lists
# Definition for singly-linked list.
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution:
def mergeKLists(self, lists: List[Optional[ListNode]]) -> List:
out_list = []