Guest User

HackerRank Sherlock and Array

a guest
Aug 14th, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | Software | 0 0
  1. class Result
  2. {
  3.  
  4.     /*
  5.      * Complete the 'balancedSums' function below.
  6.      *
  7.      * The function is expected to return a STRING.
  8.      * The function accepts INTEGER_ARRAY arr as parameter.
  9.      */
  10.  
  11.     public static string balancedSums(List<int> arr)
  12.     {
  13.         int rightSum = arr.Sum();
  14.         int leftSum = 0;
  15.        
  16.         for (var i = 0; i < arr.Count; i++)
  17.         {
  18.             rightSum -= arr[i];
  19.            
  20.             if (leftSum == rightSum)
  21.             {
  22.                 return "YES";
  23.             }
  24.            
  25.             leftSum += arr[i];
  26.         }
  27.        
  28.         return "NO";
  29.     }
  30.  
  31. }
Tags: hackerrank
Advertisement
Add Comment
Please, Sign In to add comment