정렬 02 - K번째수, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview, Heap, 힙, 정렬, sort
# Process # 1. Input numbers (int) # 2. Convert int to str # 3. Sort using value multiplied by 4, Descending direction. # 4. Handle exception case # 5. Return def solution(numbers): result = '' array_string = [] for number in numbers: array_string.append(str(number)) array_string = quicksort(array_string) for string in array_string: result += string if result.startswith('0'): result = '0' return..
정렬 01 - K번째수, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview, Heap, 힙, 정렬, sort
# Process # 1. Input array, commands # 2. Iterate all commands # 2.1. Get sub array using commands # 2.2. Get target value from subarray # 2.3. Put target_value into the result_array # 3. Return result array def solution(array, commands): result_array = [] for command in commands: temp_array = array[command[0] - 1 : command[1]] temp_array.sort() result_array.append(temp_array[command[2]-1]) retu..
힙 03 - 이중우선순위큐, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview, Heap, 힙
# Process # 1. Input operations # 2. Iterate operations # 2.1. Do operation with queue # 3. Check queue for answer # 4. Return answer def solution(operations): answer = [] array_queue = [] for operation in operations: if operation.startswith('I'): array_queue.append(int(operation[2:])) elif operation.startswith('D') and len(array_queue) > 0: if operation.endswith('-1'): pop_smallest(array_queue)..
힙 02 - 디스크컨트롤러, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview, Heap, 힙
# Process SJF(Short Job First) # 1. Input tasks [[input_time, task_time], ..] # 2. Sort using input_time # 3. Iterate till tasks is remained # 3.1. Search shortest task which input time is under time spent # 3.2. Do task and ++time # 4. Return total time / initial length of tasks import heapq import math def solution(tasks): whole_task_time = 0 time_spent = 0 len_tasks = len(tasks) # 2. tasks_so..
힙 01 - 더맵게, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview, Heap, 힙
# Process # 1. Input scoville array and threshold K # 2. Make heap queue # 3. Iterate while all scoville is over K # 3.1. Check scoville (smallest one) # 3.1.1. If passed -> done. # 3.1.2. If not -> mix foods # 3.3. Count # 4. Return answer import heapq def solution(scoville, K): count = 0 # 2. heap_scoville = [] for value in scoville: heapq.heappush(heap_scoville, value) # 3. is_done = False wh..
스택/큐 04 - 기능개발, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview
# Process # 1. Input priorities, location # 2. Make location_tracker plate for the location index I need to know # 3. Iterate while remaining priorities # 3.1. Pop first index of priority from the queue # 3.2. Check if bigger priority is exist or not # 3.2.1. If so -> change the priorites queue and location tracking queue # 3.3. Check if it's poped permanently # 3.3.1. Count answer # 3.3.2. If t..
스택/큐 03 - 기능개발, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview
# Process # 1. Input progresses and speeds # 2. Iterate while progresses is empty # 2.1. Iterate all # 2.1.1. Add all speed of work # 2.2. Iterate from begin to the value less than 100 or the end # 2.2.1. Check if it's over 99 # 2.2.1.1. If so -> pop, and count # 2.2.1.2. If not -> end of iteration # 2.3. Append count to answer # 3. Return answer[] def solution(progresses, speeds): answer = [] w..
스택/큐 02 - 주식가격, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview
# Process (list) # 1. Input prices list # 2. Iterate i from begin to the end # 2.1. Iterate j from i to the end # 2.1.1. Check if [j] is smaller than [i] # 2.1.1.1. If so - it's done # 2.1.2. Count # 2.2. Add to answer_list # 3. Return answer_list # 스택을 따로 쓰진 않고 그냥 비스므리하게 구현함 def solution(prices): answer_list = [] for i in range(0, len(prices)): isDone = False count = 0 j = i while (j < len(pric..