title: Program Find Smallest Difference Angles Two Parts Given Circle
signature: func programFindSmallestDifferenceAnglesTwoPartsGivenCircle(arr []int, n int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(arr []int, n int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(arr, n),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver([]int{4, 4, 5, 5, 13, 14, 14, 16, 19, 20, 30, 31, 32, 33, 35, 38, 38, 42, 44, 44, 48, 48, 52, 58, 60, 64, 65, 66, 68, 69, 70, 70, 71, 72, 73, 79, 81, 83, 83, 84, 86, 87, 88, 88, 91, 92, 95, 95, 98}, 
  	27, 2)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{-56, 88, -50, 70, 20, 58, 42, -56, -52, -78, 98, 20, -26, 4, 20, -66, -46, -58, 74, 74, -72, 2, 16, -78, -4, 10, 58, 60, -46, -2, 32, -96, 24, -6, 90, -64, -24, -38, 26, 66, -42, -86, 48, 92, 28, 6, -54, -6}, 
  	29, 16)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
  	25, 340)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{52, 67, 62}, 
  	1, 256)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-56, -22, 32, 42, 66}, 
  	4, 360)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0}, 
  	10, 354)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{38, 46, 58, 72}, 
  	2, 192)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{16, 62, 90, 40, 30, -56, -92, -56, 60, 42, -64, 92, -30, -70, 42, -48, -54, 54, 48, 94, -44, -46, 10, 48, 22, -24, -62, 34, 60, 24, -60, 50, 40, 34}, 
  	20, 24)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
  	37, 340)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{86, 43, 74, 84, 86, 14, 45, 7, 92, 36, 79, 13, 67, 18, 96, 77, 13, 22, 28, 36, 57, 56, 99, 57, 8, 48, 5, 79, 65, 64, 96, 6, 36, 91, 53, 55, 11, 12, 80, 99, 50, 40, 4, 9, 52, 41}, 
  	40, 0)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def program_find_smallest_difference_angles_two_parts_given_circle(arr, n):
      l = 0
      _sum = 0
      ans = 360
      for i in range(n):
          _sum += arr[i]
          while (_sum >= 180):
              ans = min(ans, (2 * abs((180 - _sum))))
              _sum -= arr[l]
              l += 1
          ans = min(ans, (2 * abs((180 - _sum))))
      return ans
source_cpp: int program_find_smallest_difference_angles_two_parts_given_circle(vector<int> arr, int n) {
    int l = 0, sum = 0, ans = 360;
    for ( int i = 0;
    i < n;
    i ++ ) {
      sum += arr [ i ];
      while ( sum >= 180 ) {
        ans = min ( ans, 2 * abs ( 180 - sum ) );
        sum -= arr [ l ];
        l ++;
      }
      ans = min ( ans, 2 * abs ( 180 - sum ) );
    }
    return ans;
  }