From 7cba3b160b468c02ab05316050e8516a96bb1397 Mon Sep 17 00:00:00 2001 From: chayan das Date: Thu, 23 Oct 2025 13:11:06 +0530 Subject: [PATCH] Create 3461. Check If Digits Are Equal in String After Operations I --- ...gits Are Equal in String After Operations I | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 3461. Check If Digits Are Equal in String After Operations I diff --git a/3461. Check If Digits Are Equal in String After Operations I b/3461. Check If Digits Are Equal in String After Operations I new file mode 100644 index 0000000..d97f52f --- /dev/null +++ b/3461. Check If Digits Are Equal in String After Operations I @@ -0,0 +1,18 @@ +class Solution { +public: + bool hasSameDigits(string s) { + int iteration = 0; // Tracks how many layers of reduction have been done + + // Continue reducing until only two digits remain + while (s.size() - iteration != 2) { + // Replace each character with the sum of adjacent digits (mod 10) + for (int i = 0; i < s.size() - 1 - iteration; i++) { + s[i] = ((s[i] - '0') + (s[i + 1] - '0')) % 10 + '0'; + } + iteration++; + } + + // Return true if the final two digits are equal + return s[0] == s[1]; + } +};