fork download
  1. using System;
  2.  
  3. class Solution
  4. {
  5. public int solution(int[] A)
  6. {
  7. int n = A.Length;
  8. int ans = int.MaxValue; // ✅ Initial large value
  9. for (int i = 0; i < n - 1; i++)
  10. {
  11. if (A[i] * A[i + 1] >= 0) // ✅ Only consider non-negative products
  12. {
  13. ans = Math.Min(ans, A[i] * A[i + 1]);
  14. }
  15. }
  16. return ans;
  17. }
  18.  
  19. // Main method for testing
  20. public static void Main()
  21. {
  22. Solution sol = new Solution();
  23.  
  24. int[] test1 = { 1, 4, 4 };
  25. Console.WriteLine(sol.solution(test1)); // Expected output: 4
  26.  
  27. int[] test2 = { -5, -2, 3, 6 };
  28. Console.WriteLine(sol.solution(test2)); // Expected output: 10 (from -5 * -2)
  29.  
  30. int[] test3 = { -3, 0, 4, 5 };
  31. Console.WriteLine(sol.solution(test3)); // Expected output: 0 (from 0 * 4)
  32.  
  33. int[] test4 = { -1, 2, -3, 4 };
  34. Console.WriteLine(sol.solution(test4)); // Expected output: 8 (from -2 * -4 if such existed)
  35.  
  36. int[] test5 = { -2, -1, 0, 1, 2 };
  37. Console.WriteLine(sol.solution(test5)); // Expected output: 0 (from -1 * 0 or 0 * 1)
  38.  
  39. int[] test6 = { 1, 4, 4, 1 };
  40. Console.WriteLine(sol.solution(test6));
  41. }
  42. }
  43.  
Success #stdin #stdout 0.07s 28956KB
stdin
10
aba
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
stdout
4
10
0
2147483647
0
4