Given 3 integers **A**, **B** and **C**, return the smallest number.

You are not allowed to use built-in functions such as **min**

**Example 1:**

Input:A= 7,B= 4,C= 9Output:4

**Example 2:**

Input:A= 3,B= 8,C= 3Output:3

The core challenge of this problem is to determine the smallest of three given integers without using built-in functions. This is a fundamental problem that helps in understanding basic conditional statements and comparisons in programming.

Common applications include scenarios where built-in functions are restricted or unavailable, and understanding the logic behind such comparisons is crucial.

Potential pitfalls include incorrect comparisons or missing conditions, which can lead to incorrect results.

To solve this problem, we can use simple conditional statements to compare the three integers. Here are the steps:

- Compare A with B and C. If A is less than or equal to both, return A.
- If the above condition is not met, compare B with A and C. If B is less than or equal to both, return B.
- If neither of the above conditions is met, return C as it is the smallest.

This approach ensures that we check all possible conditions to find the smallest number.

Here is a step-by-step breakdown of the algorithm:

- Initialize the function with three integer parameters A, B, and C.
- Use an if statement to check if A is less than or equal to both B and C. If true, return A.
- If the above condition is false, use another if statement to check if B is less than or equal to both A and C. If true, return B.
- If neither of the above conditions is true, return C.

```
public class MinimumValueOfThree {
// Function to find the minimum of three integers
public static int findMinimum(int A, int B, int C) {
// Check if A is the smallest
if (A <= B && A <= C) {
return A;
}
// Check if B is the smallest
if (B <= A && B <= C) {
return B;
}
// If neither A nor B is the smallest, return C
return C;
}
// Main method to test the function
public static void main(String[] args) {
// Test cases
System.out.println(findMinimum(7, 4, 9)); // Output: 4
System.out.println(findMinimum(3, 8, 3)); // Output: 3
}
}
```

The time complexity of this approach is O(1) because we are performing a constant number of comparisons regardless of the input size. The space complexity is also O(1) as we are not using any additional space that grows with the input size.

Potential edge cases include:

- All three numbers being the same (e.g., A = 5, B = 5, C = 5). The function should return 5.
- Two numbers being the same and the third being different (e.g., A = 3, B = 3, C = 5). The function should return 3.

These cases are handled by the conditional checks in the algorithm.

To test the solution comprehensively, consider the following test cases:

- Simple cases with distinct numbers (e.g., A = 7, B = 4, C = 9).
- Cases with two or more numbers being the same (e.g., A = 3, B = 8, C = 3).
- Edge cases with all numbers being the same (e.g., A = 5, B = 5, C = 5).

Use a variety of test cases to ensure the function works correctly in all scenarios.

When approaching such problems, consider breaking down the problem into smaller parts and solving each part step-by-step. Practice solving similar problems to improve your problem-solving skills. Understanding the logic behind comparisons and conditional statements is crucial.

In this blog post, we discussed how to find the minimum of three integers without using built-in functions. We covered the problem definition, approach, algorithm, code implementation, complexity analysis, edge cases, and testing. Understanding and solving such problems is important for developing strong problem-solving skills in programming.

For further reading and practice problems, consider the following resources: