vaibhav joshi’s Post

View profile for vaibhav joshi, graphic

2 ⭐ codechef ||1436 Leetcode rating

🚀 Todays contest starter 143C discussions🚀 1. Bit Manipulation for Counting: void solve() { ll i, n, x, cnt = 0; cin >> n >> x; for (int i = n; i > n - x; i--) { cnt += (1 << i); } for (int i = n - x; i >= 1; i--) { cnt -= (1 << i); } cout << cnt << endl; } Key Idea: Use bitwise operations to calculate the sum of powers of 2 in a specific range. Iterate and adjust the count accordingly. 2. String Comparison with Condition Checks: cpp void solve() { ll i, n, k, cnt = 0; string s, s1; cin >> n >> k; cin >> s >> s1; ll count_zero_s = 0; ll count_zero_s1 = 0; for (ll i = 0; i < n; ++i) { if (s[i] != s1[i]) { cnt++; } if (s[i] == '0') { count_zero_s++; } if (s1[i] == '0') { count_zero_s1++; } } if (s == s1 && (s == "00" || s == "11")) { cout << "YES" << endl; return; } if (count_zero_s != count_zero_s1) { cout << "NO" << endl; return; } if (n == 2 && cnt == 2 && k % 2 == 0) { cout << "NO" << endl; return; } if (cnt == 0 && k % 2 != 0 && n == 2) { cout << "NO" << endl; return; } if (cnt % 2) { cout << "NO" << endl; return; } else { if ((cnt / 2 <= k)) cout << "YES" << endl; else cout << "NO" << endl; } } Key Idea: Compare two strings and count mismatches. Check for specific conditions to determine if transformations are possible within a given number of operations. 3. Counting Logarithmic Steps: cpp void solve() { ll i, j, n, x, cnt = 0; cin >> n; int t = n; while (t > 0) { t /= 2; cnt++; } j = 2; x = 1; cout << cnt << endl; for (int i = 1; i <= n; i++) { if (i == j) { j *= 2; x++; } cout << x << " "; } } Key Idea: Calculate the number of divisions by 2 until reaching zero to determine logarithmic steps. Use this information to iterate and print values in a specific sequence. Conclusion: Each problem presented unique challenges and required distinct strategies. The key takeaway is the importance of understanding the problem constraints and leveraging different techniques like bitwise operations, string manipulation, and logarithmic calculations. Feel free to share your thoughts or ask any questions about these approaches. Happy coding! 😊 #CompetitiveProgramming #C++ #Coding #ProblemSolving #BitManipulation #Algorithms #codechef #faang #codeforces #TLE

  • No alternative text description for this image

To view or add a comment, sign in

Explore topics