Question Given two strings, find the number of common characters between them. Example For s1 = "aabcc" and s2 = "adcaa", the output should be commonCharacterCount(s1, s2) = 3. Strings have 3 common characters - 2 "a"s and 1 "c". Input/Output [execution time limit] 4 seconds (py3) [input] string s1 A string consisting of lowercase English letters. Guaranteed constraints: 1 ≤ s1.length < 15. [inp..
Question Given an array of strings, return another array containing all of its longest strings. Example For inputArray = ["aba", "aa", "ad", "vcd", "aba"], the output should be allLongestStrings(inputArray) = ["aba", "vcd", "aba"]. Input/Output [execution time limit] 4 seconds (py3) [input] array.string inputArray A non-empty array. Guaranteed constraints: 1 ≤ inputArray.length ≤ 10, 1 ≤ inputAr..
Question After becoming famous, the CodeBots decided to move into a new building together. Each of the rooms has a different cost, and some of them are free, but there's a rumour that all the free rooms are haunted! Since the CodeBots are quite superstitious, they refuse to stay in any of the free rooms, or any of the rooms below any of the free rooms. Given matrix, a rectangular matrix of i..
Question Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array. Note: sequence a0, a1, ..., an is considered to be a strictly increasing if a0 < a1 < ... < an. Sequence containing only one element is also considered to be strictly increasing. Example For sequence = [1, 3, 2, 1], the ..
4.Given an array of integers, find the pair of adjacent elements that has the largest product and return that product Example) -> For inputArray = [3, 6, -2, -5, 7, 3], the output should be adjacentElementsProduct(inputArray) = 21. 7 and 3 produce the largest product. def adjacentElementsProduct(inputArray): max_array = [] for i in range(len(inputArray)-1): max_array.append(inputArray[i]*inputAr..
본 포스팅은 프로그래머스의 어서와! 자료구조와 알고리즘은 처음이지? 강의를 듣고 정리한 것임을 참고 바랍니다. 1. sorted() 내장함수 정렬된 새로운 리스트를 얻어냄 원본 리스트는 변화가 없음 2. sort() 리스트의 메서드 해당 리스트를 정렬함 원본 리스트가 변화 ->> 정렬의 순서를 반대로 원한다면 reverse = True (내림차순) 사용 ex) L2 = sorted(L, reverse = True), L.sort(reverse=True) 리스트가 문자열로 이루어진 경우 정렬 순서는 사전 순서(알파벳 순서)를 따른다. 문자열 길이를 순서의 기준으로도 사용할 수 있다. (정렬에 사용하는 key를 지정) ex) sorted(L, key=lambda x: len(x)) 키를 지정하는 또 다른 예..
본 포스팅은 프로그래머스의 어서와! 자료구조와 알고리즘은 처음이지? 강의를 듣고 정리한 것임을 참고 바랍니다. 선형 배열 (Linear Array) 배열(Arrays) - 같은 종류의 데이터가 줄지어 늘어서있는 것을 뜻 함, 파이썬에는 따로 존재하지 않음 리스트(List) - Python의 list는 다른 프로그램의 Arrays에 비해 융통성이 있는 자료구조 Python 리스트의 index는 0부터 시작, 리스트의 요소의 길이가 달라도, 다른 타입이여도 상관이 없다. 리스트 연산은 크게 5가지로 나뉜다. (1) 원소 덧붙이기(append) (2) 끝에서 꺼내기(pop) 리스트의 (1), (2) 연산은 리스트의 길이와 무관한 상수 시간이 걸린다. O(1) (3) 원소 삽입하기(insert) 리스트를 하나 ..
1. Write a function that returns the sum of two numbers. Example) -> For param1 = 1 and param2 = 2, the output should be add(param1, param2) = 3. def add(param1, param2): return param1 + param2 2. Given a year, return the century it is in.The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc. Example) -> For..