{"id":20399306,"url":"https://github.com/sunilsoni/codility-practice","last_synced_at":"2025-04-12T13:22:19.551Z","repository":{"id":128930366,"uuid":"103723415","full_name":"sunilsoni/Codility-Practice","owner":"sunilsoni","description":"Contains Solutions for Codility training Lessons.","archived":false,"fork":false,"pushed_at":"2018-10-08T08:21:15.000Z","size":124,"stargazers_count":61,"open_issues_count":0,"forks_count":35,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T08:06:46.561Z","etag":null,"topics":["codility","codility-lessons","codility-solutions"],"latest_commit_sha":null,"homepage":"https://codility.com/programmers/lessons/1-iterations/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sunilsoni.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-16T04:04:11.000Z","updated_at":"2024-04-02T20:33:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"f2fa13ea-096f-422c-9af3-6f8bf90ea5bf","html_url":"https://github.com/sunilsoni/Codility-Practice","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunilsoni%2FCodility-Practice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunilsoni%2FCodility-Practice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunilsoni%2FCodility-Practice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunilsoni%2FCodility-Practice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunilsoni","download_url":"https://codeload.github.com/sunilsoni/Codility-Practice/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571939,"owners_count":21126548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codility","codility-lessons","codility-solutions"],"created_at":"2024-11-15T04:28:19.551Z","updated_at":"2025-04-12T13:22:19.526Z","avatar_url":"https://github.com/sunilsoni.png","language":"Java","readme":"= Codility for Programmers: \n\n\n\n== https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/[Available Lessons]\n \n\n== https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/BinaryGap[Solutions to Lesson 1: Binary Gap]\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/BinaryGap/BinaryGap.java[*Binary Gap:*] Find longest sequence of zeros in binary representation of an integer.\n\nA binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.\n\nFor example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps.\n\n[source,java]\n-----------------\nWrite a function:\n\nclass Solution { public int solution(int N); }\n-----------------\n\n\nthat, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.\n\nFor example, given N = 1041 the function should return 5, because N has binary representation 10000010001 and so its longest binary gap is of length 5.\n\nAssume that:: N is an integer within the range [1..2,147,483,647].\n\nComplexity:\nexpected worst-case time complexity is O(log(N));\nexpected worst-case space complexity is O(1).\n\n== https://github.com/sunilsoni/Codility-Practice/tree/master/src/com/codility/lessons/Arrays[Solutions to Lesson 2: Arrays]\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/Arrays/OddOccurrencesInArray.java[*Odd Occurrences In Array:*] Find value that occurs in odd number of elements.\n\nA non-empty zero-indexed array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired.\n\nFor example, in array A such that:\n[source,java]\n-----------------\n  A[0] = 9  A[1] = 3  A[2] = 9\n  A[3] = 3  A[4] = 9  A[5] = 7\n  A[6] = 9\n-----------------\nthe elements at indexes 0 and 2 have value 9,\nthe elements at indexes 1 and 3 have value 3,\nthe elements at indexes 4 and 6 have value 9,\nthe element at index 5 has value 7 and is unpaired.\nWrite a function:\n[source,java]\n-----------------\nclass Solution { public int solution(int[] A); }\n-----------------\nthat, given an array A consisting of N integers fulfilling the above conditions, returns the value of the unpaired element.\n\nFor example, given array A such that:\n[source,java]\n-----------------\n  A[0] = 9  A[1] = 3  A[2] = 9\n  A[3] = 3  A[4] = 9  A[5] = 7\n  A[6] = 9\n-----------------\nthe function should return 7, as explained in the example above.\n\nAssume that::\n\nN is an odd integer within the range [1..1,000,000];\neach element of array A is an integer within the range [1..1,000,000,000];\nall but one of the values in A occur an even number of times.\nComplexity:\n\nexpected worst-case time complexity is O(N);\nexpected worst-case space complexity is O(1), beyond input storage (not counting the storage required for input arguments).\n\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/Arrays/CyclicRotation.java[*Cyclic Rotation:*] Rotate an array to the right by a given number of steps.\nA zero-indexed array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place).\n\nThe goal is to rotate array A K times; that is, each element of A will be shifted to the right K times.\n\nWrite a function:\n[source,java]\n-----------------\nclass Solution { public int[] solution(int[] A, int K); }\n-----------------\n\nthat, given a zero-indexed array A consisting of N integers and an integer K, returns the array A rotated K times.\n\nFor example, given\n[source,java]\n-----------------\n    A = [3, 8, 9, 7, 6]\n    K = 3\n-----------------\nthe function should return [9, 7, 6, 3, 8]. Three rotations were made:\n\n\n[source,java]\n-----------------\n    [3, 8, 9, 7, 6] -\u003e [6, 3, 8, 9, 7]\n    [6, 3, 8, 9, 7] -\u003e [7, 6, 3, 8, 9]\n    [7, 6, 3, 8, 9] -\u003e [9, 7, 6, 3, 8]\n-----------------\n\n[source,java]\n-----------------\nFor another example, given\n    A = [0, 0, 0]\n    K = 1\nthe function should return [0, 0, 0]\n-----------------\nGiven:\n[source,java]\n-----------------\n    A = [1, 2, 3, 4]\n    K = 4\nthe function should return [1, 2, 3, 4]\n-----------------\nAssume that::\n\nN and K are integers within the range [0..100];\neach element of array A is an integer within the range [−1,000..1,000].\nIn your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.\n\n\n== https://github.com/sunilsoni/Codility-Practice/tree/master/src/com/codility/lessons/TimeComplexity[Solutions to Lesson 3: Time Complexity]\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/TimeComplexity/FrogJmp.java[*Frog Jump:*] Count minimal number of jumps from position X to Y.\nA small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D.\n\nCount the minimal number of jumps that the small frog must perform to reach its target.\n\nWrite a function:\n[source,java]\n-----------------\nclass Solution { public int solution(int X, int Y, int D); }\n-----------------\nthat, given three integers X, Y and D, returns the minimal number of jumps from position X to a position equal to or greater than Y.\n\nFor example, given:\n[source,java]\n-----------------\n  X = 10\n  Y = 85\n  D = 30\n-----------------\nthe function should return 3, because the frog will be positioned as follows:\n\nafter the first jump, at position 10 + 30 = 40\nafter the second jump, at position 10 + 30 + 30 = 70\nafter the third jump, at position 10 + 30 + 30 + 30 = 100\nAssume that::\n\nX, Y and D are integers within the range [1..1,000,000,000];\nX ≤ Y.\n\nComplexity:\n\nexpected worst-case time complexity is O(1);\nexpected worst-case space complexity is O(1).\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/TimeComplexity/PermMissingElem.java[*Perm Missing Element:*] Find the missing element in a given permutation.\nA zero-indexed array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing.\n\nYour goal is to find that missing element.\n\nWrite a function:\n[source,java]\n-----------------\nclass Solution { public int solution(int[] A); }\n-----------------\nthat, given a zero-indexed array A, returns the value of the missing element.\n\nFor example, given array A such that:\n[source,java]\n-----------------\n  A[0] = 2\n  A[1] = 3\n  A[2] = 1\n  A[3] = 5\n-----------------\nthe function should return 4, as it is the missing element.\n\nAssume that::\n\nN is an integer within the range [0..100,000];\nthe elements of A are all distinct;\neach element of array A is an integer within the range [1..(N + 1)].\nComplexity:\n\nexpected worst-case time complexity is O(N);\nexpected worst-case space complexity is O(1), beyond input storage (not counting the storage required for input arguments).\n\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/TimeComplexity/TapeEquilibrium.java[*Tape Equilibrium:*] Minimize the value |(A[0] + ... + A[P-1]) - (A[P] + ... + A[N-1])|.\n\nA non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a tape.\n\nAny integer P, such that 0 \u003c P \u003c N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1].\n\nThe difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])|\n\nIn other words, it is the absolute difference between the sum of the first part and the sum of the second part.\n\nFor example, consider array A such that:\n[source,java]\n-----------------\n  A[0] = 3\n  A[1] = 1\n  A[2] = 2\n  A[3] = 4\n  A[4] = 3\n-----------------\nWe can split this tape in four places:\n[source,java]\n-----------------\nP = 1, difference = |3 − 10| = 7 \nP = 2, difference = |4 − 9| = 5 \nP = 3, difference = |6 − 7| = 1 \nP = 4, difference = |10 − 3| = 7 \n-----------------\nWrite a function:\n[source,java]\n-----------------\nclass Solution { public int solution(int[] A); }\n-----------------\n\nthat, given a non-empty zero-indexed array A of N integers, returns the minimal difference that can be achieved.\n\nFor example, given:\n[source,java]\n-----------------\n  A[0] = 3\n  A[1] = 1\n  A[2] = 2\n  A[3] = 4\n  A[4] = 3\n-----------------\nthe function should return 1, as explained above.\n\nAssume that::\n\nN is an integer within the range [2..100,000];\neach element of array A is an integer within the range [−1,000..1,000].\nComplexity:\n\nexpected worst-case time complexity is O(N);\nexpected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).\n\n\n\n== https://github.com/sunilsoni/Codility-Practice/tree/master/src/com/codility/lessons/CountingElements[Solutions to Lesson 4: Counting Elements]\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/CountingElements/PermutationCheck.java[*Permutation  Check:*] Check whether array A is a permutation.\n\nA non-empty zero-indexed array A consisting of N integers is given.\n\nA permutation is a sequence containing each element from 1 to N once, and only once.\n\nFor example, array A such that:\n[source,java]\n-----------------\n    A[0] = 4\n    A[1] = 1\n    A[2] = 3\n    A[3] = 2\n-----------------\nis a permutation, but array A such that:\n[source,java]\n-----------------\n    A[0] = 4\n    A[1] = 1\n    A[2] = 3\n-----------------\nis not a permutation, because value 2 is missing.\n\nThe goal is to check whether array A is a permutation.\n\nWrite a function:\n[source,java]\n-----------------\nclass Solution { public int solution(int[] A); }\n-----------------\n\nthat, given a zero-indexed array A, returns 1 if array A is a permutation and 0 if it is not.\n\nFor example, given array A such that:\n[source,java]\n-----------------\n    A[0] = 4\n    A[1] = 1\n    A[2] = 3\n    A[3] = 2\n-----------------\nthe function should return 1.\n\nGiven array A such that:\n[source,java]\n-----------------\n    A[0] = 4\n    A[1] = 1\n    A[2] = 3\n-----------------\nthe function should return 0.\n\nAssume that::\n\nN is an integer within the range [1..100,000];\neach element of array A is an integer within the range [1..1,000,000,000].\nComplexity:\n\nexpected worst-case time complexity is O(N);\nexpected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).\n\n\n\n== https://github.com/sunilsoni/Codility-Practice/tree/master/src/main/java/com/codility/lessons/Sorting[Solutions to Lesson 6: Sorting]\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/Sorting/Distinct.java[*Distinct:*] Compute number of distinct values in an array.\n\n\nWrite a function\n\n[source,java]\n-----------------\nclass Solution { public int solution(int[] A); }\n-----------------\n\nthat, given a zero-indexed array A consisting of N integers, returns the number of distinct values in array A.\n\nAssume that::\n\nN is an integer within the range [0..100,000];\neach element of array A is an integer within the range [−1,000,000..1,000,000].\nFor example, given array A consisting of six elements such that:\n[source,java]\n-----------------\n A[0] = 2    A[1] = 1    A[2] = 1\n A[3] = 2    A[4] = 3    A[5] = 1\n-----------------\nthe function should return 3, because there are 3 distinct values appearing in array A, namely 1, 2 and 3.\n\nComplexity:\n\nexpected worst-case time complexity is O(N*log(N));\nexpected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).\n\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/Sorting/Triangle.java[*Triangle:*] Determine whether a triangle can be built from a given set of edges.\n\nA zero-indexed array A consisting of N integers is given. A triplet (P, Q, R) is triangular if 0 ≤ P \u003c Q \u003c R \u003c N and:\n[source,java]\n-----------------\nA[P] + A[Q] \u003e A[R],\nA[Q] + A[R] \u003e A[P],\nA[R] + A[P] \u003e A[Q].\n-----------------\nFor example, consider array A such that:\n[source,java]\n-----------------\n  A[0] = 10    A[1] = 2    A[2] = 5\n  A[3] = 1     A[4] = 8    A[5] = 20\n-----------------\nTriplet (0, 2, 4) is triangular.\n\nWrite a function:\n[source,java]\n-----------------\nclass Solution { public int solution(int[] A); }\n-----------------\n\nthat, given a zero-indexed array A consisting of N integers, returns 1 if there exists a triangular triplet for this array and returns 0 otherwise.\n\nFor example, given array A such that:\n[source,java]\n-----------------\n  A[0] = 10    A[1] = 2    A[2] = 5\n  A[3] = 1     A[4] = 8    A[5] = 20\n-----------------\nthe function should return 1, as explained above. Given array A such that:\n[source,java]\n-----------------\n  A[0] = 10    A[1] = 50    A[2] = 5\n  A[3] = 1\n-----------------\nthe function should return 0.\n\nAssume that::\n\nN is an integer within the range [0..100,000];\neach element of array A is an integer within the range [−2,147,483,648..2,147,483,647].\nComplexity:\n\nexpected worst-case time complexity is O(N*log(N));\nexpected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).\n\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/Sorting/MaxProductOfThree.java[*MaxProductOfThree:*] Maximize A[P] * A[Q] * A[R] for any triplet (P, Q, R).\n\nA non-empty zero-indexed array A consisting of N integers is given. The product of triplet (P, Q, R) equates to A[P] * A[Q] * A[R] (0 ≤ P \u003c Q \u003c R \u003c N).\n\nFor example, array A such that:\n[source,java]\n-----------------\n  A[0] = -3\n  A[1] = 1\n  A[2] = 2\n  A[3] = -2\n  A[4] = 5\n  A[5] = 6\n-----------------\ncontains the following example triplets:\n[source,java]\n-----------------\n(0, 1, 2), product is −3 * 1 * 2 = −6\n(1, 2, 4), product is 1 * 2 * 5 = 10\n(2, 4, 5), product is 2 * 5 * 6 = 60\n-----------------\nYour goal is to find the maximal product of any triplet.\n\nWrite a function:\n[source,java]\n-----------------\nclass Solution { public int solution(int[] A); }\n-----------------\n\nthat, given a non-empty zero-indexed array A, returns the value of the maximal product of any triplet.\n\nFor example, given array A such that:\n[source,java]\n-----------------\n  A[0] = -3\n  A[1] = 1\n  A[2] = 2\n  A[3] = -2\n  A[4] = 5\n  A[5] = 6\n-----------------\nthe function should return 60, as the product of triplet (2, 4, 5) is maximal.\n\nAssume that::\n\nN is an integer within the range [3..100,000];\neach element of array A is an integer within the range [−1,000..1,000].\nComplexity:\n\nexpected worst-case time complexity is O(N*log(N));\nexpected worst-case space complexity is O(1), beyond input storage (not counting the storage required for input arguments).\n\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/Sorting/NumberOfDiscIntersections.java[*Number Of Disc Intersections:*] Compute the number of intersections in a sequence of discs.\n\nWe draw N discs on a plane. The discs are numbered from 0 to N − 1. A zero-indexed array A of N non-negative integers, specifying the radiuses of the discs, is given. The J-th disc is drawn with its center at (J, 0) and radius A[J].\n\nWe say that the J-th disc and K-th disc intersect if J ≠ K and the J-th and K-th discs have at least one common point (assuming that the discs contain their borders).\n\nThe figure below shows discs drawn for N = 6 and A as follows:\n[source,java]\n-----------------\n  A[0] = 1\n  A[1] = 5\n  A[2] = 2\n  A[3] = 1\n  A[4] = 4\n  A[5] = 0\n-----------------\n\nThere are eleven (unordered) pairs of discs that intersect, namely:\n\ndiscs 1 and 4 intersect, and both intersect with all the other discs;\ndisc 2 also intersects with discs 0 and 3.\nWrite a function:\n[source,java]\n-----------------\nclass Solution { public int solution(int[] A); }\n-----------------\n\nthat, given an array A describing N discs as explained above, returns the number of (unordered) pairs of intersecting discs. The function should return −1 if the number of intersecting pairs exceeds 10,000,000.\n\nGiven array A shown above, the function should return 11, as explained above.\n\nAssume that:: \n\nN is an integer within the range [0..100,000];\neach element of array A is an integer within the range [0..2,147,483,647].\nComplexity:\n\nexpected worst-case time complexity is O(N*log(N));\nexpected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).\n\n\n\n== https://github.com/sunilsoni/Codility-Practice/tree/master/src/main/java/com/codility/lessons/StacksQueues[Solutions to Lesson 7: Stacks and Queues]\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/StacksQueues/Brackets.java[*Brackets:*] Determine whether a given string of parentheses (multiple types) is properly nested.\n\nA string S consisting of N characters is considered to be properly nested if any of the following conditions is true:\n\nS is empty;\nS has the form \"(U)\" or \"[U]\" or \"{U}\" where U is a properly nested string;\nS has the form \"VW\" where V and W are properly nested strings.\nFor example, the string \"{[()()]}\" is properly nested but \"([)()]\" is not.\n\nWrite a function:\n\n[source,java]\n-----------------\nclass Solution { public int solution(String S); }\n-----------------\n\nthat, given a string S consisting of N characters, returns 1 if S is properly nested and 0 otherwise.\n\nFor example, given S = \"{[()()]}\", the function should return 1 and given S = \"([)()]\", the function should return 0, as explained above.\n\nAssume that::\n\nN is an integer within the range [0..200,000];\nstring S consists only of the following characters: \"(\", \"{\", \"[\", \"]\", \"}\" and/or \")\".\n\nComplexity::\n\nexpected worst-case time complexity is O(N);\nexpected worst-case space complexity is O(N) (not counting the storage required for input arguments).\n\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/StacksQueues/Nesting.java[*Nesting:*] Determine whether a given string of parentheses (single type) is properly nested.\n\nA string S consisting of N characters is called properly nested if:\n\nS is empty;\nS has the form \"(U)\" where U is a properly nested string;\nS has the form \"VW\" where V and W are properly nested strings.\nFor example, string \"(()(())())\" is properly nested but string \"())\" isn't.\n\nWrite a function:\n[source,java]\n-----------------\nclass Solution { public int solution(String S); }\n-----------------\n\nthat, given a string S consisting of N characters, returns 1 if string S is properly nested and 0 otherwise.\n\nFor example, given S = \"(()(())())\", the function should return 1 and given S = \"())\", the function should return 0, as explained above.\n\nAssume that::\n\nN is an integer within the range [0..1,000,000];\nstring S consists only of the characters \"(\" and/or \")\".\n\nComplexity::\n\nexpected worst-case time complexity is O(N);\nexpected worst-case space complexity is O(1) (not counting the storage required for input arguments).\n\n\n* https://github.com/sunilsoni/Codility-Practice/blob/master/src/main/java/com/codility/lessons/StacksQueues/StoneWall.java[*StoneWall:*] Cover \"Manhattan skyline\" using the minimum number of rectangles.\n\nYou are going to build a stone wall. The wall should be straight and N meters long, and its thickness should be constant; however, it should have different heights in different places. The height of the wall is specified by an array H of N positive integers. H[I] is the height of the wall from I to I+1 meters to the right of its left end. In particular, H[0] is the height of the wall's left end and H[N−1] is the height of the wall's right end.\n\nThe wall should be built of cuboid stone blocks (that is, all sides of such blocks are rectangular). Your task is to compute the minimum number of blocks needed to build the wall.\n\nWrite a function:\n\n[source,java]\n-----------------\nclass Solution { public int solution(int[] H); }\n-----------------\n\nthat, given an array H of N positive integers specifying the height of the wall, returns the minimum number of blocks needed to build it.\n\nFor example, given array H containing N = 9 integers:\n[source,java]\n-----------------\n  H[0] = 8    H[1] = 8    H[2] = 5\n  H[3] = 7    H[4] = 9    H[5] = 8\n  H[6] = 7    H[7] = 4    H[8] = 8\n-----------------\nthe function should return 7. The figure shows one possible arrangement of seven blocks.\n\n\n\nAssume that::\n\nN is an integer within the range [1..100,000];\neach element of array H is an integer within the range [1..1,000,000,000].\n\nComplexity::\n\nexpected worst-case time complexity is O(N);\nexpected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunilsoni%2Fcodility-practice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunilsoni%2Fcodility-practice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunilsoni%2Fcodility-practice/lists"}