All Questions
130 questions
0
votes
3
answers
101
views
How to write an algorithm that count the duration of time without repetitions
We have an array of date interval arrays:
[[start_date, end_date], [], ...]
For example:
[
[01.02.2020, 01.05.2020], # 3 months
[01.01.2020, 01.10.2020], # 9 month, but we cant count ...
0
votes
2
answers
548
views
How to iterate over an array of hashes in Ruby to compare each member with the following members in the array?
So, I have an array of hashes, let's use this as an example
arr = [
{:series=>"GOT", :rating=>"Good", :type=>"Fantasy"},
{:series=>"BB", :rating=...
0
votes
2
answers
359
views
circularArrayRotation algorithm ruby
I am using hacker rank and I do not understand why my ruby code only works for one test case out of like 20. Here is the question:
John Watson knows of an operation called a right circular rotation ...
1
vote
1
answer
4k
views
Returning the least number of multiplications it took to find an adjacent pair of duplicate numbers
I'm not very good with algorithms and I am completely stuck on this and have not been able to find the help I was looking for. The problem I am trying to solve is the following:
Have the function ...
-1
votes
2
answers
121
views
Compare subarrays of 2-dimensional array in Ruby and show result array with existing and missed items
You have a 2-dimensional array of strings:
[
["AAA", "BBB", "CCC", "DDD"],
["BBB", "CCC", "DDD"],
["AAA", &...
0
votes
1
answer
119
views
Ruby - Understanding string vs array comparison
I'm working on a practice problem in Ruby. I already have the answer (below) but I'm not sure I understand how exactly one part of the answer works, specifically, how does new_word evaluate to a ...
0
votes
1
answer
493
views
Sorting a string by last names: Ruby
Finding this coding challenge rather tricky and can't seem to figure out what method I should add to explicitly sort the last names of a string.
Current solution:
def sort_reindeer reindeer_names
...
-4
votes
4
answers
378
views
How to detect concurrent dates
I need an algorithm which looks simple, but I still can't think about a well optimised way to do to do this.
I have the following json object:
[
{
"start": "2000-...
0
votes
4
answers
105
views
How do I create a multidimensional array from an array in Ruby?
I need to create a multidimensional array from an array.
For example, let's say the initial array = [1,2,3,4,5,6]
I need a multidimensional array of
[ [1],[1,2],[1,2,3],[1,2,3,4],[1,2,3,4,5],[1,2,...
5
votes
3
answers
256
views
How to optimise code that parses a 2-d array in Ruby
Note: This question poses a problem that I have already solved, however I feel my solution is very rudimentary and that other people, like myself, would benefit from a discussion with input from more ...
3
votes
1
answer
104
views
What does it mean when you set an array[index] equal to quotation marks?
I've been working on a problem where the goal is to take a string and return the longest repeated pattern if a pattern is present. For example, if the string is "aabbbaa", "yes aa" would be returned. ...
0
votes
2
answers
209
views
Find missing random amount of numbers in array with duplicates
I should have a complete array of numeric identifiers like this one:
a = [3, 4, 5, 6, 7, 8, 9, 10]
But instead, I have a a messed up array in random order, with duplicates and missing numbers like ...
-2
votes
2
answers
145
views
Ruby Split array in sub arrays that contain only different values [closed]
I have an array of the following form:
[20, 20, 21, 21, 21, 21]
I'm trying to find a way to split the array in sub arrays that contain only different values.
For example:
[[20,21], [20,21], [21], [...
1
vote
6
answers
747
views
Ruby - how to slice an array and sum its elements on a condition
I can't find a way to achieve the following:
given an array of Integers
multiply every second number
sum all the integers
I tried to use Enumerble#each_slice but still no idea on how to call Array#sum ...
0
votes
1
answer
46
views
How do you maintain an index when you sort two index synced (paired) arrays?
I have two arrays that I need to keep the index pairs together:
arr1 = [17,9,8,20,14,16]
arr2 = [27,13,10,10,24,18]
I want to return them both as:
arr1 = [8,9,14,16,17,20]
arr2 = [10,13,24,18,27,10]
...