Computer Science/Algorithm with Code (18) 썸네일형 리스트형 [HackerRank] Preparation_Kit (02. Counting Valleys) An avid hiker keeps meticulous records of their hikes. During the last hike that took exactly steps steps, for every step it was noted if it was an uphill, U, or a downhill, D step. Hikes always start and end at sea level, and each step up or down represents a 1 unit change in altitude. We define the following terms:A mountain is a sequence of consecutive steps above sea level, starting with a s.. [HackerRank] Preparation_Kit (01. Sales by Match) There is a large pile of socks that must be paired by color. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are.Examplen = 7ar = [1,2,1,2,1,3,2]There is one pair of color 1 and one of color 2. There are three odd socks left, one of each color.The number of pairs is 2.Function DescriptionComplete the sockMerchant functi.. Leet Code (2405. Amazon Spring '23 HF) 2405. Optimal partition of String Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once. Return the minimum number of substrings in such a partition.Note that each character should belong to exactly one substring in a partition. Example 1:Input: s = "abacaba"Output:.. Leet Code (1492. Amazon Spring '23 HF) 1492. The kth Factor of n You are given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0.Consider a list of all factors of n sorted in ascending order, return the kth factor in this list or return -1 if n has less than k factors.: The kth factor (약수) of the n. * Check The Test_Cases (Exceptions)Could you solve this problem in less than O(n) comp.. Hacker Rank_5/54 tests (Easy, Lonely Integer) Given an array of integers, where all elements but one occur twice, find the unique element.Examplea = [1, 2, 4, 3, 3, 2, 1]The unique element is 4.func lonelyinteger(a: [Int]) -> Int { var dics = [Int : Int]() for i in a { if dics[i] == nil { dics[i] = 1 } else { dics[i]! += 1 } } return dics.first{ $0.value == 1 }!.key} Hacker Rank_4/54 tests (Easy, Sparse Array) There is a collection of input strings and a collection of query strings. For each query string, determine how many times it occurs in the list of input strings. Return an array of the results. Examplequeries = [a', 'b', c'd']strings = [a', b, c'd']return => [1, 0, 1] func matchingStrings(strings: [String], queries: [String]) -> [Int] { // Hashmap - Dictionary // Arr - size/order //var dic.. Hacker Rank_3/54 tests (Easy, Time Conversion) Given a time in -hour AM/PM format, convert it to military (24-hour) time.func timeConversion(s: String) -> String { //split / components / subscript / index var ans = s.map { $0 } // or copy-inout if s.contains("P") { ans.replaceSubrange(0...1, with: String(Int(s.split(separator: ":")[0])!+12)) if ans[0] == "2" && ans[1] == "4" { ans.replaceSubrange(0...1, .. Hacker Rank_2/54 tests (Easy, Min-Max Sum) While solving basic problems from the beginning, I should also practice summarizing problems written in English.And plan to organize Swift grammar thoroughly starting from the basics.Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two spa.. 이전 1 2 3 다음