본문 바로가기

전체 글

(62)
up_stage interview prep 1. NEXT vs REACT REACT NEXT - Library - React Framework - Client-side Rendering (HTML sent to browser, and subsequent updates rendered on browser - Server-side Rendering (Rendered on Server-side before sending to client) and Static Site Generation (Pre-rendered at buildtime - No built-in routing - Third-party library for routing (ex. React Router) - File System based Routing ('pages' directory d..
#54. Spiral Matrix class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: result = [] top, bottom, left, right = 0, len(matrix) - 1, 0, len(matrix[0]) - 1 while top
#62. Unique Paths class Solution: def uniquePaths(self, m: int, n: int) -> int: dp = [[1] * n for _ in range(m)] for i in range(1, m): for j in range(1, n): # Calculate the number of unique paths for cell (i, j) dp[i][j] = dp[i-1][j] + dp[i][j-1] return dp[m-1][n-1] # if not m or not n: # return 0 # grid = [[0] * n for _ in range(m)] # grid[0][0] = 1 # directions = [(1, 0), (0, 1)] # queue = deque([(0, 0)]) # whi..
#55. Jump Game You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last index, or false otherwise. def canJump(self, nums: List[int]) -> bool: maxReach = 0 for i in range(len(nums)): if i > maxReach: # Cannot reach last index return False maxReach = max(..
#53. Maximum Subarray Given an integer array nums, find the subarray with the largest sum, and return its sum. Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: The subarray [4,-1,2,1] has the largest sum 6. Example 2: Input: nums = [1] Output: 1 Explanation: The subarray [1] has the largest sum 1. Example 3: Input: nums = [5,4,-1,7,8] Output: 23 Explanation: The subarray [5,4,-1,7,8] has the la..
#34. Find First and Last Position of Element in Sorted Array Given an array of integers nums sorted in non decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. You must write an algorithm with O(log n) runtime complexity. def searchRange(self, nums: List[int], target: int) -> List[int]: first = -1 last = -1 for i in range(0, len(nums)): if (target != nums[i]): continue if (f..
#13. Roman to Integer Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two ones added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II. Roman numerals are usually written largest to smallest from left to right. However..
#2. Add Two Numbers You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example 1: Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] Explanation: 342 +..
#36. Valid Sudoku Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: 1. Each row must contain the digits 1-9 without repetition. 2. Each column must contain the digits 1-9 without repetition. 3. Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition. Example 1: Input: board = [["5","3",".",".","7",".",".","...
#49. Group Anagrams Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Example 1: Input: strs = ["eat","tea","tan","ate","nat","bat"] Output: [["bat"],["nat","tan"],["ate","eat","tea"]] Example 2: Input: strs = [""] O..
#46. Permutations Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Example 1: Input: nums = [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] Example 2: Input: nums = [0,1] Output: [[0,1],[1,0]] Example 3: Input: nums = [1] Output: [[1]] class Solution: def permute(self, nums: List[int]) -> List[List[int]]: def DFS(visited, pat..
#22. Generate Parentheses (backtrack, stack) Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1: Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] Example 2: Input: n = 1 Output: ["()"] class Solution: def generateParenthesis(self, n: int) -> List[str]: stack = [] ANS = [] def backTrack(openN, closedN): if n == openN == closedN: # Valid parenthesis ANS.append(..
#19. Remove Nth Node From End of List Given the head of a linked list, remove the nth node from the end of the list and return its head. Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Example 2: Input: head = [1], n = 1 Output: [] Example 3: Input: head = [1,2], n = 1 Output: [1] # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Sol..
#15. 3Sum Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. Example 1: Input: nums = [-1,0,1,2,-1,-4] Output: [[-1,-1,2],[-1,0,1]] Explanation: nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0. nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) ..
#11. Container With Most Water [Two Ptr] You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Example 1: Input: height = [1,8,6,2,5,4,8,3,7] Output: 49 Explanation..
#7. Reverse Integer Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0. Assume the environment does not allow you to store 64-bit integers (signed or unsigned). Example 1: Input: x = 123 Output: 321 Example 2: Input: x = -123 Output: -321 Example 3: Input: x = 120 Output: 21 class Solution: ..
#5. Longest Palindromic Substring (even/odd ptrs) Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Explanation: "aba" is also a valid answer. Example 2: Input: s = "cbbd" Output: "bb" Constraints: 1 = 0 and right < len(s) and s[left] == s[right]: left-=1 right+=1 print(left,right, s[left+1:right]) return s[left+1:right] longest = "" for i in range(len(s)): odd = expand(i,i) if len(odd)..
# 17. Letter Combinations of a Phone Number [BACKTRACK, DFS] Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. Example 1: Input: digits = "23" Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] Example 2: Input: digits = "..
#19. Remove Nth Node From End of List [Sliding window] Given the head of a linked list, remove the nth node from the end of the list and return its head. Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Example 2: Input: head = [1], n = 1 Output: [] Example 3: Input: head = [1,2], n = 1 Output: [1] # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Sol..
#3. Longest Substring Without Repeating Characters [MEDIUM] Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: s = "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Notice that the ans..
Data Analysis STATISTICS 1. REGRESSION: 연속된 독립변수와 종속변수의 관계 및 경향성을 찾는 방법 --> Least Squares (오차를 최소화하는 모델 찾기) X: [1, 2, 3, 4, 5] Y: [2, 4, 5, 4, 5] 1. FIND DEVIATION OF X and Y deviation of x = X - x̄ deviation of y = Y - ȳ deviation of x: [-2, -1, 0, 1, 2] deviation of y: [-2, 0, 1, 0, 1] 2. CALCULATE PRODUCT OF DEV deviation of x * deviation of y product of deviations: [4, 0, 0, 0, 2] 3. CALCULATE SQUARED DE..
LINEAR ALGEBRA 1. COVARIANCE MATRIX STEP 1: X: [2, 3, 5, 7, 10] Y: [6, 9, 12, 15, 18] Step 2: Calculate the Means (μx and μy): μx = (2 + 3 + 5 + 7 + 10) / 5 = 5.4 μy = (6 + 9 + 12 + 15 + 18) / 5 = 12 Step 3: Calculate the Covariance: Cov(X, Y) = Σ((xi - μx) * (yi - μy)) / (n - 1) = (20.4 + 7.2 + 0 + 4.8 + 27.6) / (5 - 1) = 59 / 4 ≈ 14.75 Cov(X, X) = Σ((xi - μx)^2) / (n - 1) = ((-3.4)^2 + (-2.4)^2 + (-0.4)^2 + ..
MySQL WHERE DATE LIKE '2022-01%' 1. Date Format WHERE DATE_FORMAT(DATE, '%Y-%m') BETWEEN '2022-08' and '2022-10' 2. SELECT 열_이름 FROM 테이블_이름 JOIN B ON A.PK = B.PK WHERE 조건식 GROUPBY 열_이름 HAVING 조건식 ORDERBY 열_이름 LIMIT 숫자 3. ex) 음식 종류별 예약횟수 --> SUBQUERY where (food_type, reservations) in (select food_type, max(reservations) from rest_info group by food_type ) 4. 2022년 10월 추출 WHERE DATE LIKE '2022-10%' WHE..
React Topics 1. Components and Props Controlled Components Controlled components are React components whose form elements (such as input fields) are controlled by React state. This means that the component's state holds the current value of the form element, and any changes to the value are handled by updating the state. Here's an example: import React, { useState } from 'react'; function ControlledComponent..
Bank.java [Spring] --> REST API --> React UI import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.Map; @RestController @RequestMapping("/api/bank") public class BankController { private Map users; private Map accounts; private List cards; private int lastUserId; private int lastAccountId; private int lastCardI..
Algorithms 1. BINARY SEARCH def binary_search(arr, target): low = 0 high = len(arr) - 1 while low max_sum: max_sum = window_sum return max_sum # Example usage: my_list = [4, 2, 1, 7, 8, 1, 2, 8, 1, 0] window_size = 3 max_sum = sliding_window(my_list, window_size) print("Maximum sum within a window of size", window_size, ":", max_sum) 4. BRUTE FORCE def brute_force(arr, target): for i in range(len(arr)): fo..
#3. TicTacToe GameChallenge def GameChallenge(strArr): temp = [e for e in strArr if e != ""] #board = [temp[i:i+3] for i in range(0, len(temp), 3)] #ans = -1 for i in range(0,9,4): row = [strArr[i],strArr[i+1],strArr[i+2]] if row.count("X") == 2 and row.count("-") == 1: return i + row.index("-") if row.count("O") == 2 and row.count("-") == 1: return i + row.index("-") for i in range(3): col = [strArr[i],strArr[i+4],strArr[..
#2 ArrayChallenge # Have the function ArrayChallenge(strArr) read the array of strings stored in strArr, # which will contain 2 elements: the first element will be a sequence of characters, # and the second element will be a long string of comma-separated words, in alphabetical order, # that represents a dictionary of some arbitrary length. # For example: strArr can be: ["hellocat", "apple,bat,cat,goodbye,hello,y..
RESTful API [JAVA/SPRING] --> ReactJS (Client) --> DB PART 1: API SERVER [SPRING] Step 1: Defining API Endpoints --> Map Each Method with HTTP Verbs import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api") public class UserController { @GetMapping("/users") public String getAllUsers() { // Logic to retrieve all users from the database return "List of all users"; } @GetMapping("/users/{id}") public String getUserById..
JAVA RESTful API [FINAL] 1. Define API Endpoints // BankAccountController.java @RestController @RequestMapping("/accounts") public class BankAccountController { @Autowired private BankAccountService bankAccountService; @GetMapping public List getAllAccounts() { return bankAccountService.getAllAccounts(); } @GetMapping("/{accountID}") public BankAccount getAccountById(@PathVariable String accountID) { return bankAccountS..