Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
1 answer
106 views

Swift: Find neighbor-elements within an array

I need a function which finds the left and right neighbor-element within an integer-array, based upon a given index. If the given element is 0, then it shall return largest index as left neighbor. ...
michael.zech's user avatar
  • 5,022
4 votes
1 answer
106 views

Swift Arrays: Write a rotate-right function

Task: Write a function which rotates all elements of a given array to the right. Example: [1, 2, 3] => [3, 1, 2] My solution: ...
michael.zech's user avatar
  • 5,022
3 votes
1 answer
177 views

Swift - efficient array searching

I am trying to find a way to search an Int array (all numbers are > 0) and identify sequences where the sum of each element is a specific number. One element can ...
koen's user avatar
  • 179
5 votes
3 answers
295 views

Sum of natural numbers below threshold

I have this code: ...
Shum's user avatar
  • 53
3 votes
2 answers
436 views

Optimize Leetcode 239. Sliding Window Maximum using Swift

LeetCode problem 239. Sliding Window Maximum You are given an array of integers nums, there is a sliding window of size k which ...
Shawn Frank's user avatar
3 votes
1 answer
343 views

Unwrapping optionals for max of a 2D array in swift

I'm working in swift and I've got a custom class Array2D to handle fixed-width, two-dimensional arrays of integers. What I'm trying to do is write a simple, ideally-...
Zeph's user avatar
  • 133
4 votes
1 answer
1k views

Find minimum count of items where sum of them is X from an array

I recently faced an interview question where you have to find minimum needed items from an array that can added together to generate X value. For example giving: <...
Mojtaba Hosseini's user avatar
3 votes
2 answers
4k views

Working with Arrays in Swift

It's an exercise from a Swift-course I'm currently taking. You are given an array of integers. Make an additional array named computedNumbers. computedNumbers should multiply each element in the ...
michael.zech's user avatar
  • 5,022
3 votes
1 answer
1k views

Swift function to find a specific set of combinations of 3 digits within a larger integer array

I asked this question on Stack Overflow and was directed here. I'm working on a function that will help me quickly find all the upper structure triads (3-note chord) that I can add to a 4-note 7th ...
Jacob Smolowe's user avatar
3 votes
3 answers
506 views

Efficient way of flat mapping a range of a multidimensional random access collection

I've recently answered a question about reading elements from an array of arrays. A way it could be interpreted is that the OP wanted to read a range that could span over multiple subarrays of the 2D ...
ielyamani's user avatar
  • 889
1 vote
2 answers
1k views

A scalable way to remove duplicates from Arrays without extensions in Swift 4

This method is an attempt at removing duplicates from arrays without the use of extensions. ...
user avatar
4 votes
1 answer
2k views

Swift - Finding longest binary gap of a given integer

I recently had the chance to try Codility's algorithm training, and the very first one in the list is finding the longest binary gap of a given integer. I tried to implement this in Swift, and after ...
badhanganesh's user avatar
4 votes
1 answer
165 views

"What To Do" App

I am starting to build up my portfolio, so I am starting to build projects whenever an idea pops up in my head. So, I decided to build an app that helps you decide what to do. Basically how it works ...
Mamadou Coulibaly's user avatar
4 votes
2 answers
469 views

Initializing an Array of Alternating Values

My goal in this project is to make something that can—as, quickly, effectively, and efficiently as Array(repeating: , count: )—initialize an ...
Noah Wilder's user avatar
7 votes
1 answer
14k views

Grouping Date Objects by year and month

I have an array of date objects, which I want to group by year and month. The data structure I have chosen for my target is an array of arrays of Date objects. Two Date objects should be in the same ...
Fang's user avatar
  • 617

15 30 50 per page