Update appNew update is available. Click here to update.
About
🛠️ Skilled in Java, HTML, CSS, JS & ReactJS. 🔍 Dive deep into Data Structures and Algorithms to craft efficient solutions. 💡 Fueled by a passion for Spark AR, bringing imagination to life. 🎓 Proud...
Chitkara University 2025
Java - Default language
My Stats
EXP gained
yellow-spark
106957
Level
9 (Sage)
Community stats
Discussions
0
Upvotes
4
Know more
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
1647
Total problems solved
1377
Easy
248
Moderate
21
Hard
1
Ninja
Jan Jan Feb Feb Mar Mar Apr Apr May May Jun Jun Jul Jul Aug Aug Sep Sep Oct Oct Nov Nov Dec Dec

Current streak:

61 days

Longest streak:

61 days

Less

More

Achievements
5
Ronin
Topics
Bit Manipulation
Greedy
+ 3 more
7
Samurai
Topics
Stacks & Queues
Sorting
+ 5 more
2
Sensei
Topics
Linked List
+ 1 more
10
Sensei
Guided path
ChatGPT
Oops in java
+ 8 more

College monthly badge

2 Times topper

1376 average partcipants
Discussions
Evaluation of postfix expression - Java Solution
Interview problems
import java.util.*;

public class Solution {

	static final long MOD = 1000000007;

	public static long modInverse(long a) {
		long m = MOD;
		long y = 0, x = 1;
		while (a > 1) {
			long quotient = a / m;
			long remainder = a % m;

			a = m;
			m = remainder;

			long temp = y;
			y = x - quotient * y;
			x = temp;
		}

		return (x + MOD) % MOD;
	}

	public static int evaluatePostfix(String[] exp) {
		Stack<Long> stack = new Stack<>();

		for (String str : exp) {
			switch (str) {
				case "+":
					stack.push((stack.pop() + stack.pop()) % MOD);
					break;
				case "-":
					long subtractor = stack.pop();
					long difference = (stack.pop() - subtractor + MOD) % MOD;
					stack.push(difference);
					break;
				case "*":
					stack.push((stack.pop() * stack.pop()) % MOD);
					break;
				case "/":
					long inverse = modInverse(stack.pop());
					stack.push((stack.pop() * inverse) % MOD);
					break;
				default:
					stack.push(Long.parseLong(str));
					break;
			}
		}

		return stack.peek().intValue();
	}
}
profile
SamarthJain
Published On 15-Oct-2023
50 views
0 replies
1 upvotes
Easy Java Code
Interview problems
import java.util.*;
import java.io.*;

public class Solution {
    public static Boolean isReflectionEqual(String s) {
        String str = "AHIMOTUVWXY";
        for (char ch : s.toCharArray()) {
            if (str.indexOf(ch) == -1)
                return false;
        }
        return new StringBuilder(s).reverse().toString().equals(s);
    }
}
profile
SamarthJain
Published On 29-Sep-2023
89 views
0 replies
1 upvotes
Easy Java Solution
Interview problems
import java.util.*;
import java.io.*;

public class Solution {

    private static String count(String ans) {
        StringBuilder temp = new StringBuilder();
        int count = 1;
        for (int i = 1; i < ans.length(); i++) {
            if (ans.charAt(i) == ans.charAt(i - 1))
                count++;
            else {
                temp.append(count).append(ans.charAt(i - 1));
                count = 1;
            }
        }
        temp.append(count).append(ans.charAt(ans.length() - 1));
        return temp.toString();
    }

    public static String writeAsYouSpeak(int n) {
        
        String ans = "1";
        for (int i = 2; i <= n; i++) {
            ans = count(ans);
        }
        return ans;
    }
}
profile
SamarthJain
Published On 27-Sep-2023
14 views
0 replies
1 upvotes
Java Solution Using BitMasking
Interview problems
import java.util.*;
import java.io.*;

public class Solution {
    static int[] detectOdd(int n, int nums[]) {
        
        int xor = 0;
        for (int i : nums) {
            xor ^= i;
        }

        int x = 0, y = 0;
        int setBit = xor & -xor;

        for (int i : nums) {
            if ((i & setBit) == 0) {
                x ^= i;
            } else {
                y ^= i;
            }
        }
        if(x < y)
            return new int[]{x,y};
        return new int[]{y,x};
    }
}
profile
SamarthJain
Published On 27-Sep-2023
34 views
0 replies
1 upvotes
Easy Java Solution
Interview problems
import java.util.*;
import java.io.*;


public class Solution {
    public static int countColumns(String[] strings) {
        int count = 0;
        for (int i = 0; i < strings[0].length(); i++) {
            boolean ans = false; // initialized to false


            for (int j = 0; j < strings.length - 1; j++) {
                if (strings[j].charAt(i) > strings[j + 1].charAt(i)) {
                    ans = true; // mark as unsorted column
                    break;
                }
            }
            count += ans ? 1 : 0;
        }
        return count;
    }
}
profile
SamarthJain
Published On 27-Sep-2023
30 views
0 replies
1 upvotes