This file contains 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 static int func(PriorityQueue<Integer> que) | |
{ | |
while(que.size()>5) | |
{ | |
que.remove(); | |
} | |
int sum=0; | |
for(int i:que) | |
{ |
This file contains 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[] sortArrayByParity(int[] nums) { | |
int[] ans = new int[nums.length]; | |
int k=nums.length-1; | |
int j=0; | |
for(int i=0;i<nums.length;i++) | |
{ | |
if(nums[i] %2 == 1) | |
{ | |
ans[k] = nums[i]; |
This file contains 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 arrayPairSum(int[] nums) { | |
int sum =0; | |
Arrays.sort(nums); | |
// Brute Technique, Accepted, 20ms | |
// for(int i=0;i<nums.length;i+=2) | |
// { | |
// int n = nums[i]; |
This file contains 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 heightChecker(int[] heights) { | |
int count=0; | |
int[] expected = new int[heights.length]; | |
for(int i=0;i<heights.length;i++) | |
{ | |
expected[i] = heights[i]; | |
} | |
Arrays.sort(expected); | |
This file contains 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 minProductSum(int[] nums1, int[] nums2) { | |
Arrays.sort(nums1); | |
Arrays.sort(nums2); | |
int sop=0; | |
for(int i=0;i<nums1.length;i++) | |
{ | |
sop+= nums1[i] * nums2[nums1.length-1 -i]; | |
} |
This file contains 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 List<List<Integer>> threeSum(int[] nums) { | |
Arrays.sort(nums); | |
List<List<Integer>> res = new ArrayList(); | |
for(int i=0;i<nums.length -2;i++) | |
{ | |
if(i== 0 || (i>0 && nums[i] != nums[i-1])) | |
{ | |
int sum = 0-nums[i]; |
This file contains 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[][] merge(int[][] intervals) { | |
Stack<int[]> st = new Stack<>(); | |
Arrays.sort(intervals,(int[] a, int[] b)->{ | |
return a[0] - b[0]; | |
}); | |
for(int i=0;i<intervals.length;i++) | |
{ | |
int[] res = intervals[i]; | |
int s = res[0]; |
This file contains 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 numJewelsInStones(String jewels, String stones) { | |
HashMap<Character, Integer> hm = new HashMap<>(); | |
for(int i=0;i<stones.length();i++) | |
{ | |
char ch = stones.charAt(i); | |
if(hm.containsKey(ch)) | |
{ | |
int count = hm.get(ch); |
This file contains 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 String defangIPaddr(String address) { | |
String ans = ""; | |
for(int i=0;i<address.length();i++) | |
{ | |
char ch = address.charAt(i); | |
if(ch == '.') | |
{ | |
ans+="[.]"; | |
} |
This file contains 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 String restoreString(String s, int[] indices) { | |
char[] arr = new char[indices.length]; | |
String str = ""; | |
for(int i=0;i<s.length();i++) | |
{ | |
char ch = s.charAt(i); | |
int p = indices[i]; | |
arr[p] = ch; |