FLOW014 - Editorial

Problem Link - Grade The Steel Practice Problem in 500 to 1000 difficulty problems

Problem Statement:

We are given the following conditions to grade the steel:

  • Hardness of the steel must be greater than 50.
  • Carbon content of the steel must be less than 0.7.
  • Tensile strength must be greater than 5600.

Based on the above conditions, the grades are assigned as follows:

  • Grade 10: If all three conditions are met.
  • Grade 9: If conditions (1) and (2) are met.
  • Grade 8: If conditions (2) and (3) are met.
  • Grade 7: If conditions (1) and (3) are met.
  • Grade 6: If only one condition is met.
  • Grade 5: If none of the conditions are met.

Approach:

  • Evaluating Conditions: We will directly check each of the conditions using if-else statements for each test case:
    • If all three conditions are met, print 10.
    • If only two conditions are met, we check for each possible combination of conditions and assign the corresponding grade (9, 8, or 7).
    • If only one condition is met, assign grade 6.
    • If no conditions are met, assign grade 5.
  • Using if-else Ladder: The conditions are evaluated in a sequence where:
    • The highest grade is checked first (Grade 10 for all three conditions).
    • Then, the remaining combinations of two conditions are checked (Grade 9, 8, or 7).
    • If only one condition is met, grade 6 is assigned.
    • Finally, if none of the conditions are met, grade 5 is assigned.

Complexity:

  • Time Complexity: O(1) the conditions are checked using a constant number of operations.
  • Space Complexity: O(1) No extra space is used.