Here is a Python implementation that matches the description (sorry, I don't understand C, but I think it's pretty simple code). We can track the registered return values ββand indexes for each section in question to understand how it works.
Output:
a = [5, 9, 3, 5, 5, 21, 5, 7, 17, 5, 5, 5] print f(a, 0, len(a) - 1) """ n: 3; l: None; r: 3; L: (0, 1); R: (2, 2) n: 3; l: 5; r: 21; L: (3, 4); R: (5, 5) n: 6; l: None; r: 5; L: (0, 2); R: (3, 5) n: 3; l: None; r: 17; L: (6, 7); R: (8, 8) n: 3; l: 5; r: 5; L: (9, 10); R: (11, 11) n: 6; l: None; r: 5; L: (6, 8); R: (9, 11) n: 12; l: None; r: 5; L: (0, 5); R: (6, 11) 5 """
source share