Sort by

recency

|

50 Discussions

|

  • + 0 comments
    int main() {
        int odd = 0, even = 0;
        int n; cin >> n; int a[n];
        for(int i = 0; i < n; i++) { 
            cin >> a[i];
            if(a[i]%2 == 0) even++;
            else odd++;
        }
        if(n == 1 & odd == 1) { cout << -1; return 0; }
        cout << min(odd%2, odd%2 + even%2);
        return 0;
    }
    
  • + 0 comments

    Simple Python Solution:

    def smallestSizeSubsequence(n, A):
        total = sum(A)
        result = 0 if total%2 == 0 else 1 if len(A)>1 else -1
        return result
    
  • + 1 comment

    static int smallestSizeSubsequence(int n, int[] a) { // Return the size of the smallest subsequence to remove if(n==1) return -1; int sum=0; for(int i=0;i

  • + 0 comments

    Java Solution O(N)

    if(total sum = even number) then print 0
    else
      total sum is an odd number. 
      We know that sum of two odd numbers is always even num
      Since the total sum is odd, the number of odd numbers is   
      definetely odd, deleting one of the odd numbers would
      result in an even sum.
      If we have only one number which is odd, then print -1
      
      Simple Number Theory
    
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int sum=0;
    for(int i = 0; i < n; i++){
        sum += in.nextInt();
    }
    System.out.println((sum%2==0)?0:(n==1)?-1:1);
    
  • + 0 comments

    if input n=5 and A[A_i]={1,2,3,4,5} then how is output comes 5. i didn't get this explanation section. can u give me detail explanation