완전탐색 02 - 모의고사, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview, Heap, 힙, 정렬, sort, search
# Process # 1. Input numbers # 2. Make sieve depending on length of numbers # 3. Make all number permutations # 4. Check if each number made is prime number or not # 4.1. If so -> ++count # 4. Return count # 파이썬 문법 잘 몰라서 까다로운게 있었음 # 순열 재귀구현은 해보면 좋을 듯함 from itertools import permutations def solution(numbers): count = 0 # 2. sieve_length = '' for i in range(len(numbers)): sieve_length += '9' prime..
완전탐색 01 - 모의고사, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview, Heap, 힙, 정렬, sort, search
# Process # 1. Input answers # 2. Make math throwers answers # 3. Compare answers and math throwers' answers # 4. Get people who got highest score # 5. Return result def solution(answers): result = [] # 2. math_thrower_1 = [] math_thrower_2 = [] math_thrower_3 = [] exam_problems = len(answers) for i in range(1, exam_problems+1): remainder_of_5 = i % 5 remainder_of_8 = i % 8 remainder_of_10 = i %..
탐욕법 02 - 조이스틱, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview, Heap, 힙, 정렬, sort, greedy
// ASCII 65~ 90 (A~ Z) // Process #2 (greedy) // 1. Input name // 2. Make list or Map using Index and DiffCount of diff things // 3. Iterate while all list is removed // 3.1. Move to shorter distance (left or right) // 3.2. Count moving distance // 3.3. Count char diff // 3.4. Remove that thing from the list // 4. Return result count import java.util.*; class Solution { public int solution(Strin..
정렬 03 - H Index, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview, Heap, 힙, 정렬, sort
# Process # 1. Input citations list # 3. Iterate from maximum h index to lowest h index (0) # 3.1. Count how many papers are having citation count over h index # 3.2. Check if count is over h_index or not # 3.3. If so -> h_index return # 4. Finish # # performace 올려야함 def solution(citations): for index in range(len(citations), 0, -1): count = 0 for i in range(0, len(citations)): if citations[i] >..
정렬 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..