Sherlock and Array

  • + 2 comments

    Hello friends,

    Sherlock and Array hackerrank problem can be solved easily by deriving a linear equation. The complexity of Sherlock and Array hackerrank solution is O(n)

    If interested to know more about the generic algorithm in details-

    click here for the video explanation of generic algorithm with complexity analysis.

    or you can click on the image too to follow youtube tutorial.

    Here is the working solution:-

    source code :

    static String balancedSums(List<Integer> arr) {
    		int x = 0;
    		int sum = 0;
    		for (int a : arr) {
    			sum += a;
    		}
    
    		for (int y : arr) {
    			if (2 * x == sum - y) {
    				return "YES";
    			}
    			x = x + y;
    		}
    		return "NO";
    
    	}
    

    Would really appreciate your feedback like, dislike , comment etc. on my video.

    Do not forget to upvote, if you find it useful.