We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0b6e77b commit b40888dCopy full SHA for b40888d
README.md
@@ -1310,8 +1310,8 @@ In order to achieve greater coverage and encourage more people to contribute to
1310
</a>
1311
</td>
1312
<td> <!-- Ruby -->
1313
- <a href="./CONTRIBUTING.md">
1314
- <img align="center" height="25" src="./logos/github.svg" />
+ <a href="./src/ruby/min_max_dc.rb">
+ <img align="center" height="25" src="./logos/ruby.svg" />
1315
1316
1317
<td> <!-- JavaScript -->
src/ruby/min_max_dc.rb
@@ -0,0 +1,22 @@
1
+require 'test/unit/assertions'
2
+include Test::Unit::Assertions
3
+
4
+def min_max_dc(vector, start_index, end_index)
5
+ if start_index == end_index
6
+ return [vector[start_index], vector[start_index]]
7
+ end
8
9
+ middle = (start_index + end_index) / 2
10
+ left_min, left_max = min_max_dc(vector, start_index, middle)
11
+ right_min, right_max = min_max_dc(vector, middle + 1, end_index)
12
13
+ min = left_min < right_min ? left_min : right_min
14
+ max = left_max > right_max ? left_max : right_max
15
16
+ [min, max]
17
+end
18
19
+assert_equal([1, 5], min_max_dc([1, 2, 3, 4, 5], 0, 4))
20
+assert_equal([14, 55], min_max_dc([13, 55, 42, 14, 15], 1, 3))
21
+assert_equal([13, 13], min_max_dc([13, 55, 42, 14, 15], 0, 0))
22
+assert_equal([14, 15], min_max_dc([13, 55, 42, 14, 15], 3, 4))
0 commit comments