Skip to content

Instantly share code, notes, and snippets.

View Tan12d's full-sized avatar
🎯
Focusing

Tanmoy Das Tan12d

🎯
Focusing
View GitHub Profile
@Tan12d
Tan12d / Leetcode 2294 | Partition Array Such That Maximum Difference Is K.java
Created June 19, 2025 10:01
Leetcode 2294 | Partition Array Such That Maximum Difference Is K
class Solution {
public int partitionArray(int[] nums, int k)
{
Arrays.sort(nums);
int min = nums[0];
int count=1;
for(int i=1;i<nums.length;i++)
{
@Tan12d
Tan12d / Leetcode 2966 | Divide Array Into Arrays With Max Difference.java
Created June 18, 2025 12:51
Leetcode 2966 | Divide Array Into Arrays With Max Difference
class Solution {
public int[][] divideArray(int[] nums, int k)
{
int n = nums.length;
int res[][] = new int[n/3][3];
Arrays.sort(nums);
int p=0;
@Tan12d
Tan12d / Leetcode 3405 | Count the Number of Arrays with K Matching Adjacent Elements.java
Created June 17, 2025 13:17
Leetcode 3405 | Count the Number of Arrays with K Matching Adjacent Elements
class Solution {
private static final int MOD = (int)1e9+7;
private int[] fact;
private int[] invFact;
private int binaryExp(long a, long b)
{
long res = 1;
while(b>0)
@Tan12d
Tan12d / Leetcode 2016 | Maximum Difference Between Increasing Elements.java
Created June 16, 2025 12:44
Leetcode 2016 | Maximum Difference Between Increasing Elements
class Solution {
public int maximumDifference(int[] nums)
{
int diff = -1;
int minElement = nums[0];
int n = nums.length;
for(int j=1;j<n;j++)
@Tan12d
Tan12d / Leetcode 1432 | Max Difference You Can Get From Changing an Integer.java
Created June 15, 2025 04:35
Leetcode 1432 | Max Difference You Can Get From Changing an Integer
class Solution {
public int maxDiff(int num)
{
String s1 = Integer.toString(num);
String s2 = Integer.toString(num);
char c = '0';
int n = s1.length();
@Tan12d
Tan12d / Leetcode 2566 | Maximum Difference by Remapping a Digit.java
Created June 14, 2025 13:03
Leetcode 2566 | Maximum Difference by Remapping a Digit
class Solution {
public int minMaxDifference(int num)
{
char leftMostDigit = '0';
String number = Integer.toString(num);
for(int i=0;i<number.length();i++)
{
if(number.charAt(i)!='9')
@Tan12d
Tan12d / Leetcode 2616 | Minimize the Maximum Difference of Pairs.java
Created June 13, 2025 12:52
Leetcode 2616 | Minimize the Maximum Difference of Pairs
class Solution {
public int minimizeMax(int[] nums, int p)
{
Arrays.sort(nums);
int n = nums.length;
int l = 0;
int h = nums[n-1];
@Tan12d
Tan12d / Leetcode 3423 | Maximum Difference Between Adjacent Elements in a Circular Array.java
Created June 12, 2025 12:47
Leetcode 3423 | Maximum Difference Between Adjacent Elements in a Circular Array
class Solution {
public int maxAdjacentDistance(int[] nums)
{
int n = nums.length-1;
int res = Integer.MIN_VALUE;
for(int i=0;i<n;i++)
{
int diff = Math.abs(nums[i]-nums[i+1]);
@Tan12d
Tan12d / Leetcode 3445 | Maximum Difference Between Even and Odd Frequency II.java
Created June 11, 2025 14:47
Leetcode 3445 | Maximum Difference Between Even and Odd Frequency II
class Solution {
private int getState(int count_a, int count_b)
{
int parity_a = count_a&1;
int parity_b = count_b&1;
if(parity_a==0 && parity_b==0) return 0; // even even
if(parity_a==0 && parity_b==1) return 1; // even odd
@Tan12d
Tan12d / Leetcode 3442 | Maximum Difference Between Even and Odd Frequency I.java
Created June 10, 2025 17:03
Leetcode 3442 | Maximum Difference Between Even and Odd Frequency I
class Solution {
public int maxDifference(String s)
{
int freq[] = new int[26];
for(char c: s.toCharArray())
{
freq[c-'a']++;
}