DEV Community

Somuya Khandelwal
Somuya Khandelwal

Posted on

DAY 12 Tackling Math-Based Challenges

Hello Everyone!

I am Somuya Khandelwal, here to share my progress from Day 2 of Week 3 in my competitive programming journey. Today, I explored Math-based problems, which required logical reasoning and efficient computation. Math problems often demand a mix of creativity and precision, and today’s challenges helped sharpen those skills.


What I Worked On Today

  1. Palindrome Number (Easy Difficulty)

    • Determine if a given integer reads the same backward as forward.
    • Approach:
      • Converted the integer to a string and compared it with its reverse.
      • For a more efficient approach, reversed only half of the number (using modulo and division) and compared it with the first half.
    • What I Learned:
      • Efficient techniques avoid the need for extra space by using mathematical operations instead of string manipulation.
      • Edge cases like negative numbers and numbers ending in zero (e.g., 10) require special handling.
  2. Plus One (Easy Difficulty)

    • Given a non-negative integer represented as an array, increment the integer by one.
    • Approach:
      • Started from the last digit and handled carry propagation by iterating backward.
      • Created a new array if the carry extended beyond the most significant digit.
    • What I Learned:
      • Handling carry propagation efficiently is key in array-based arithmetic problems.
      • Problems involving edge cases (e.g., all digits being 9) emphasize the importance of thorough testing.
  3. Factorial Trailing Zeros (Medium Difficulty)

    • Count the number of trailing zeros in the factorial of a given number n.
    • Approach:
      • Counted the number of factors of 5 in the numbers from 1 to n, as each factor of 5 pairs with a factor of 2 to create a trailing zero.
    • What I Learned:
      • Factorial problems often involve patterns in prime factors rather than computing the factorial directly.
      • Efficient solutions avoid unnecessary computations by leveraging mathematical insights.

What I Learned Today

  1. Optimized Mathematical Computations:

    • Problems like Palindrome Number and Factorial Trailing Zeros reinforced the importance of minimizing computations through clever mathematical insights.
  2. Handling Edge Cases:

    • Problems involving integers (e.g., Plus One) require careful handling of edge cases like large carries or unusual input values.
  3. Iterative and Space-Efficient Approaches:

    • Whenever possible, avoiding unnecessary space usage (e.g., converting integers to strings) improves efficiency and scalability.
  4. Breaking Down Problems into Steps:

    • Math problems often benefit from breaking the logic into clear, manageable steps for better understanding and debugging.

Reflections and Challenges

The Factorial Trailing Zeros problem stood out as the most interesting today. It required a shift in perspective from direct computation to identifying patterns in prime factors. Debugging Plus One was also a learning experience, as managing carry propagation backward through an array took careful planning.

Today’s problems strengthened my logical reasoning skills and gave me confidence in handling number-based challenges efficiently.


Looking Ahead

Tomorrow, I’ll continue exploring Math-based problems, including Sqrt(x), Pow(x, n), and the more challenging Max Points on a Line. These tasks will help me dive deeper into mathematical computations and geometry-based problems.

Thank you for following my journey! Stay tuned for more updates as I continue tackling exciting challenges in competitive programming.

Top comments (0)