This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int maxDiff(int num) | |
{ | |
String s1 = Integer.toString(num); | |
String s2 = Integer.toString(num); | |
char c = '0'; | |
int n = s1.length(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int minimizeMax(int[] nums, int p) | |
{ | |
Arrays.sort(nums); | |
int n = nums.length; | |
int l = 0; | |
int h = nums[n-1]; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int maxDifference(String s) | |
{ | |
int freq[] = new int[26]; | |
for(char c: s.toCharArray()) | |
{ | |
freq[c-'a']++; | |
} | |
NewerOlder