Skip to main content

Posts

Roman Number to Integer

This website describe common assumption and failure during gfg coding. python Failed class Solution: def romanToDecimal(self, s): # code here val={ '':1, 'X':10, 'L':50, 'M':1000, 'C':100, 'V':5 } sum=0 s=s[::-1] count=0 for i in s: if count==1: count=0 sum-=val[i] else: sum+=val[i] count+=1 return sum Reason Your current implementation of `romanToDecimal()` has the right spirit, but the logic for subtractive notation (like `IV`, `IX`, `XL`, etc.) is off. You're using a `count` flag, which doesn't reliably detect when subtraction should occur. --- ⚠️ Issues: 1. Incorrect subtraction logic : Roman numerals subtract only when a smaller value precedes a larger...

Balancing brackets

we are going to make the logic for isbalanced function correct.This article is part of my efforts where i have made many mistakes while thinking about problem solution which iam just recording over here.Finally i will also have the correct anwser in the same language.As it is self explanatory no Explantion. Test Case 1 Python Failure class Solution: def isequal(self,f,s): ok=[['(',')'], ['[',']'], ['{','}'], ] for i in ok: s=s.replace(i[1],i[0]) if f==s: return True else : return False def isBalanced(self, s): # code here s=s.strip() s.replace(" ","") n=len(s) #should be even if n%2!=0: return False m=n//2 f=s[:m] t=s[m:] t=t[::-1] return self.isequal(f,t) My above program got fa...

Longest unique substring

  Test Case 1 In the brute-force approach to generating substrings using nested loops, maintaining a hashmap that counts each character's occurrence as 1 (e.g., setting counts to 1 regardless of actual frequency) is invalid. Proper substring generation and validation require accurately tracking character counts in the hashmap rather than assuming all characters occur only once. geekforgeeks eekforgeeks ekforgeeks kforgeeks forgeeks orgeeks rgeeks geeks eeks eks ks s Test Case 2 From the following output, what we actually need is a contiguous substring of characters that satisfies our problem constraints. For example, in the second case, the longest substring without repeating characters is 'ksforg' or 'stoare'—these substrings are contiguous and contain no repeating characters. geekforgeeks eekforgeek ekforgee kforge forg or o Test Case 3 We can use a fixed-size sliding window to find substrings. Starting with a window of fixed size, we keep decreasing the w...

Day 1 WEB3

Day 1: Exploring Web3 Today I started exploring Web3. I learned that it's possible to build a trading bot and host it on cloud platforms like Azure and Google Cloud. Since I'm a college student, I also applied for the GitHub Student Developer Pack—and I got it! I heard about trying out EigenLayer. I installed the MetaMask wallet, but I’m not sure how to connect it to EigenLayer or what steps to follow next. Since I’m in India, I looked into platforms like CoinDCX and Binance as potential options. But why did I choose them? That's something I’ll explore more tomorrow. Right now, I don't have any funds in my MetaMask wallet, so I’ll need to sort that out before doing any real transactions. let's look Day 2. Ihave updated the way the Conclusion Today i have took the look the front line correction error . What's Next I will make a azure python script function to run my tradingbot and this will be a important step how much iam delay i d...

Free database for beginners for prototype online

For free online databases suitable for beginners in India, here are some reliable options that support SQL and work well for prototyping: Firebase Realtime Database / Firestore Firebase offers a limited free tier and is easy to set up for quick prototypes. It provides both SQL-like Firestore and NoSQL Realtime Database options. The free plan includes 1GB storage and basic analytics. Firebase Console Supabase Supabase is an open-source alternative to Firebase with a PostgreSQL backend, making it a solid choice for SQL beginners. The free tier provides up to 500MB of database space, unlimited API requests, and real-time capabilities. Supabase PlanetScale Based on MySQL, PlanetScale is great for beginners and offers a free plan with 5GB storage and a user-friendly interface. It’s especially suitable for scalable prototypes and integrates well with modern frameworks. PlanetScale ElephantSQL ElephantSQL offers a free tier for PostgreSQL databases with 20MB storage. It’s easy to use and prov...

Move zeros to End

 Index Problem is we need to move all the zeros to the right and non-zeros to the left. Move Zeros to End Approaches we can follow are: 1st Approch :  1. Your approach of swapping each 0 element with the end ( j pointer) could work, but it requires some adjustments to handle the indices correctly. However, it’s less efficient than moving the non-zero elements to the front as it repeatedly swaps each 0 with elements toward the end, making it potentially  O ( n 2 ) O(n^2) O ( n 2 ) in the worst case due to unnecessary swaps. Here's a refined version of your approach to help clarify the issues and make it function correctly: Adjusted Code Using End-Pointer Swapping Initialize j to nums.size() - 1 (the last index). Traverse from the beginning, and for each 0 , swap it with nums[j] , then decrement j . However, keep in mind that this will cause the relative order of non-zero elements to change. class Solution { public:     void moveZeroes(vector<int>&...

how to use .json file in react

 Reading a .json file in a React application is quite straightforward. Here are the steps to do it: Create a JSON file : First, create a JSON file with some data. For example, let’s name it data.json and place it in the src folder of your React project. { "users" : [ { "id" : 1 , "name" : "John Doe" } , { "id" : 2 , "name" : "Jane Smith" } ] } Import the JSON file : In your React component, import the JSON file. import React from 'react' ; import data from './data.json' ; const App = ( ) => { return ( < div > < h1 > User List </ h1 > < ul > {data.users.map(user => ( < li key = {user.id} > {user.name} </ li > ))} </ ul > </ div > ); }; export default App ; Run your React app : Start your React application using npm start or yarn start , and yo...