using System;
class Solution
{
public int solution(int[] A)
{
int n = A.Length;
int ans = int.MaxValue; // ✅ Initial large value
for (int i = 0; i < n - 1; i++)
{
if (A[i] * A[i + 1] >= 0) // ✅ Only consider non-negative products
{
ans = Math.Min(ans, A[i] * A[i + 1]);
}
}
return ans;
}
// Main method for testing
public static void Main()
{
Solution sol = new Solution();
int[] test1 = { 1, 4, 4 };
Console.WriteLine(sol.solution(test1)); // Expected output: 4
int[] test2 = { -5, -2, 3, 6 };
Console.WriteLine(sol.solution(test2)); // Expected output: 10 (from -5 * -2)
int[] test3 = { -3, 0, 4, 5 };
Console.WriteLine(sol.solution(test3)); // Expected output: 0 (from 0 * 4)
int[] test4 = { -1, 2, -3, 4 };
Console.WriteLine(sol.solution(test4)); // Expected output: 8 (from -2 * -4 if such existed)
int[] test5 = { -2, -1, 0, 1, 2 };
Console.WriteLine(sol.solution(test5)); // Expected output: 0 (from -1 * 0 or 0 * 1)
int[] test6 = { 1, 4, 4, 1 };
Console.WriteLine(sol.solution(test6));
}
}
dXNpbmcgU3lzdGVtOwoKY2xhc3MgU29sdXRpb24KewogICAgcHVibGljIGludCBzb2x1dGlvbihpbnRbXSBBKQogICAgewogICAgICAgIGludCBuID0gQS5MZW5ndGg7CiAgICAgICAgaW50IGFucyA9IGludC5NYXhWYWx1ZTsgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIOKchSBJbml0aWFsIGxhcmdlIHZhbHVlCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuIC0gMTsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKEFbaV0gKiBBW2kgKyAxXSA+PSAwKSAgICAgICAgICAgICAgICAgICAgLy8g4pyFIE9ubHkgY29uc2lkZXIgbm9uLW5lZ2F0aXZlIHByb2R1Y3RzCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGFucyA9IE1hdGguTWluKGFucywgQVtpXSAqIEFbaSArIDFdKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIC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