Skip to content

Instantly share code, notes, and snippets.

View Debarpita02's full-sized avatar
🏠
Working from home

Debarpita Dutta Debarpita02

🏠
Working from home
View GitHub Profile
class T {
public long endTime;
public int roomId;
public T(long endTime, int roomId) {
this.endTime = endTime;
this.roomId = roomId;
}
}
class Solution {
import java.util.PriorityQueue;
class Solution {
public int furthestBuilding(int[] heights, int bricks, int ladders) {
PriorityQueue<Integer> ladderUsed = new PriorityQueue<>();
for (int i = 0; i < heights.length - 1; i++) {
int diff = heights[i + 1] - heights[i];
if (diff > 0) {
if (ladderUsed.size() < ladders) {
import java.util.*;
class Solution {
public int findLeastNumOfUniqueInts(int[] arr, int k) {
Map<Integer, Integer> freqMap = new HashMap<>();
for (int num : arr) {
freqMap.put(num, freqMap.getOrDefault(num, 0) + 1);
}
List<Integer> frequencies = new ArrayList<>(freqMap.values());
class Solution {
public long largestPerimeter(int[] nums) {
Arrays.sort(nums);
long[] prefixSum = new long[nums.length];
prefixSum[0] = nums[0];
for (int i = 1; i < prefixSum.length; i++) {
prefixSum[i] = nums[i] + prefixSum[i - 1];
}
long result = Integer.MIN_VALUE;
class Solution {
public int[] rearrangeArray(int[] nums) {
int n = nums.length, pi = 0, ni = 1;
int[] ans = new int[n];
for (int ele : nums) {
if (ele >= 0) {
ans[pi] = ele;
pi += 2;
} else {
ans[ni] = ele;
public class Solution {
public String firstPalindrome(String[] strings) {
for (String s : strings) {
if (isPalindrome(s)) {
return s;
}
}
return ""; // If no palindromic string found
}
class Solution {
public int cherryPickup(int[][] grid) {
int m = grid.length;
int n = grid[0].length;
int[][][] dp = new int[m][n][n]; // dp[i][j1][j2] stores the maximum cherries two robots can pick starting from (i, j1) and (i, j2)
for (int i = m - 1; i >= 0; i--) {
for (int j1 = 0; j1 < n; j1++) {
for (int j2 = 0; j2 < n; j2++) {
int cherries = grid[i][j1] + (j1 != j2 ? grid[i][j2] : 0); // Cherries picked by both robots
class Solution {
public int countSubstrings(String s) {
int count = 0;
for (int i = 0; i < s.length(); i++) {
count += countPalindromes(s, i, i); // Odd length palindromes
count += countPalindromes(s, i, i + 1); // Even length palindromes
}
return count;
}
import java.util.Arrays;
class Solution {
public int numSquares(int n) {
if (n <= 0) return 0;
int[] dp = new int[n + 1];
Arrays.fill(dp, Integer.MAX_VALUE);
dp[0] = 0;
import java.util.*;
class Solution {
public String frequencySort(String s) {
if (s == null || s.length() == 0)
return "";
// Count frequency of each character
Map<Character, Integer> freqMap = new HashMap<>();
for (char c : s.toCharArray()) {