본문 바로가기

append11

0211. Remove duplicates from list Define a function that removes duplicates from an array of numbers and returns it as a result. The order of the sequence has to stay the same. Solution: def distinct(seq: list[int]) -> list[int]: result = [] for i in seq: if i not in result: result.append(i) return result def distinct(seq: list[int]) -> list[int]: return sorted(set(seq), key=seq.index) def distinct(seq: list[int]) -> list[int]: .. 2023. 2. 12.
0209. Sort Out The Men From Boys Scenario Now that the competition gets tough it will Sort out the men from the boys . Men are the Even numbers and Boys are the odd!alt!alt Task Given an array/list [] of n integers , Separate The even numbers from the odds , or Separate the men from the boys!alt!alt Notes Return an array/list where Even numbers come first then odds Since , Men are stronger than Boys , Then Even numbers in ascen.. 2023. 2. 9.
0121. esreveR Write a function reverse which reverses a list (or in clojure's case, any list-like data structure) (the dedicated builtin(s) functionalities are deactivated) Solution: def reverse(lst): result = list() for _ in range(len(lst)): result.append(lst.pop()) return result 2023. 1. 21.
1020. Convert a string to an array Write a function to split a string and convert it into an array of words. Examples (Input ==> Output): "Robin Singh" ==> ["Robin", "Singh"] "I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"] Solution: from typing import List def string_to_array(s: str) -> List[str]: return split(s) def split(s: str, c: str = " ") -> List[str]: list, ci = [], 0 for i.. 2022. 10. 20.
Sum of odd numbers Description: Given the triangle of consecutive odd numbers: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 ... Calculate the sum of the numbers in the nth row of this triangle (starting at index 1) e.g.: (Input --> Output) 1 --> 1 2 --> 3 + 5 = 8 Solution: 1. Add up all 'n' numbers. 2. Find the odd number by the added number. 3. It returns after adding 'n' odd numbers from the last. def row_sum_odd_num.. 2022. 4. 28.
How Green Is My Valley? Description: Input : an array of integers. Output : this array, but sorted in such a way that there are two wings: the left wing with numbers decreasing, the right wing with numbers increasing. the two wings have the same length. If the length of the array is odd the wings are around the bottom, if the length is even the bottom is considered to be part of the right wing. each integer l of the le.. 2022. 4. 4.