├── Day04_SortAnArray.java ├── Day11_SmallestEvenMultiple ├── Day14_RotateString.java ├── Day09_SingleNumber.java ├── Day22_NumberOf1Bits.java ├── Day29_PowerOfFour.java ├── Day12_SumMultiples.java ├── Day07_ReverseString.java ├── Day27_MissingNumber.java ├── Day08_FindTheDifference.java ├── Day10_SoreOfAString.java ├── Day24_ReverseInteger.java ├── Day16_ShuffleString.java ├── Day26_AddDigits.java ├── Day30_HappyNumber.java ├── Day19_Convert1DArrayInto2DArray.java ├── Day17_ClearDigits.java ├── Day23_Pow(x,n).java ├── Day01_SortThePeople.java ├── Day25_ReverseBits.java ├── Day15_PlusOne.java ├── Day21_SumOfDigitsOfStringAfterCovert.java ├── Day13_PowerOfTwo.java ├── Day18_LemonadeChange.java ├── Day28_ThirdMaximumNumber.java ├── Day02_SortArrayByIncreasingFrequency.java ├── Day20_FindTheStudentThatWillReplaceTheChalk.java ├── Day03_SortTheJumbledNumbers.java ├── README.md ├── Day06_MinimumCostToConvertString.java └── Day05_FindTheCitySmallestNoOFNeibours.java /Day04_SortAnArray.java: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortArray(self, nums: List[int]) -> List[int]: 3 | return sorted(nums) 4 | 5 | -------------------------------------------------------------------------------- /Day11_SmallestEvenMultiple: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int smallestEvenMultiple(int n) { 3 | if(n%2==0) return n; 4 | else return n*2; 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Day14_RotateString.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean rotateString(String s, String goal) { 3 | 4 | if(s.length()!=goal.length()) return false; 5 | String str=s+s; 6 | return str.contains(goal); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Day09_SingleNumber.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int singleNumber(int[] nums) { 3 | int x=0; 4 | for(int i=0;i0) 5 | { 6 | if(n%2==1) a+=1; 7 | n/=2; 8 | } 9 | return a; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Day29_PowerOfFour.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPowerOfFour(int n) { 3 | if(n<=0) return false; 4 | while(n>1) 5 | { 6 | if(n%4!=0) return false; 7 | n=n/4; 8 | } 9 | return true; 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Day12_SumMultiples.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int sumOfMultiples(int n) { 3 | int s=0; 4 | for(int i=3;i<=n;i++) 5 | { 6 | if(i%3==0 || i%5==0 || i%7==0){ 7 | s=s+i; 8 | } 9 | } 10 | return s; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Day07_ReverseString.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void reverseString(char[] s) { 3 | int l=s.length-1,i; 4 | for(i=0;i Integer.MAX_VALUE || sum 0) { 10 | sum = sum + (int) Math.pow(n % 10, 2); 11 | n = n / 10; 12 | } 13 | return isHappy(sum); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Day19_Convert1DArrayInto2DArray.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[][] construct2DArray(int[] original, int m, int n) { 3 | int a[][] = new int[m][n]; 4 | int k=0; 5 | if(m*n!=original.length) return new int[0][0]; 6 | 7 | for(int i=0;i='0'&& s.charAt(i)<='9'){ 6 | sb.deleteCharAt(sb.length()-1); 7 | 8 | } 9 | else{ 10 | sb.append(s.charAt(i)); 11 | } 12 | } 13 | return sb.toString(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Day23_Pow(x,n).java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public double myPow(double x, int n) { 3 | 4 | double ans = 1.0; 5 | long nTemp = n; 6 | 7 | if(n < 0) 8 | nTemp = nTemp * -1; 9 | 10 | while(nTemp > 0){ 11 | if(nTemp % 2 == 0){ 12 | x *= x; 13 | nTemp /=2; 14 | } 15 | else{ 16 | ans *= x; 17 | nTemp--; 18 | } 19 | } 20 | return n < 0 ? 1 / ans : ans; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Day01_SortThePeople.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String[] sortPeople(String[] names, int[] heights) { 3 | HashMap map = new HashMap(); 4 | for(int i = 0;i=0;i--){ 11 | res[j] = map.get(heights[i]); 12 | j++; 13 | } 14 | return res; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Day25_ReverseBits.java: -------------------------------------------------------------------------------- 1 | 2 | // space 3 | public class Solution { 4 | // you need treat n as an unsigned value 5 | public int reverseBits(int n) { 6 | int result =0; 7 | for(int i=0;i<32;i++) 8 | { 9 | result <<= 1; 10 | result |= (n&1); 11 | n >>= 1; 12 | } 13 | return result; 14 | 15 | } 16 | } 17 | 18 | // time 19 | public class Solution { 20 | // you need treat n as an unsigned value 21 | public int reverseBits(int n) { 22 | return Integer.reverse(n); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Day15_PlusOne.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] plusOne(int[] digits) { 3 | int n=digits.length-1; 4 | digits[n]+=1; 5 | int m=digits[n]; 6 | while(n>=0 && m==10){ 7 | if(n==0){ 8 | digits = new int[digits.length+1]; 9 | digits[n]=1; 10 | return(digits); 11 | } 12 | else{ 13 | digits[n-1]+=1; 14 | } 15 | digits[n]=0; 16 | n--; 17 | m=digits[n]; 18 | } 19 | return(digits); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Day21_SumOfDigitsOfStringAfterCovert.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int getLucky(String s, int k) { 3 | 4 | StringBuilder number = new StringBuilder(); 5 | for (char x : s.toCharArray()) { 6 | number.append(x-96); 7 | } 8 | 9 | while (k > 0) { 10 | int temp = 0; 11 | for (char x : number.toString().toCharArray()) { 12 | temp += x - '0'; 13 | } 14 | number = new StringBuilder(String.valueOf(temp)); 15 | k--; 16 | } 17 | return Integer.parseInt(number.toString()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Day13_PowerOfTwo.java: -------------------------------------------------------------------------------- 1 | // space complexity : O(n) 2 | // time complexity : O(logN) 3 | class Solution { 4 | public boolean isPowerOfTwo(int n) { 5 | int i=1,j=0; 6 | while(i<=n && j<=31) 7 | { 8 | if(i==n) return(true); 9 | i=i*2; 10 | j++; 11 | } 12 | return(false); 13 | } 14 | } 15 | 16 | // space complexity : O(n) 17 | // time complexity : O(logN) 18 | class Solution { 19 | public boolean isPowerOfTwo(int n) { 20 | if(n<=0) return(false); 21 | while(n%2==0) 22 | { 23 | n/=2; 24 | } 25 | return(n==1); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Day18_LemonadeChange.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean lemonadeChange(int[] bills) { 3 | int five=0; 4 | int ten =0; 5 | for(int i=0;i0) ten-=10; 12 | else five-=10; 13 | five-=5; 14 | } 15 | else{ 16 | ten+=10; 17 | five-=5; 18 | } 19 | if(five<0 || ten<0) return(false); 20 | } 21 | return(five>=0 && ten>=0); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Day28_ThirdMaximumNumber.java: -------------------------------------------------------------------------------- 1 | 2 | class Solution { 3 | public int thirdMax(int[] nums) { 4 | long max1=Long.MIN_VALUE; 5 | long max2=Long.MIN_VALUE; 6 | long max3=Long.MIN_VALUE; 7 | for(int num : nums){ 8 | if(num>max1){ 9 | max3 = max2; 10 | max2 = max1; 11 | max1 = num; 12 | }else if(max1>num && num>max2){ 13 | max3 = max2; 14 | max2 = num; 15 | }else if(max2>num && num>max3){ 16 | max3=num; 17 | } 18 | } 19 | return max3 != Long.MIN_VALUE ? (int) max3 : (int) max1; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Day02_SortArrayByIncreasingFrequency.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] frequencySort(int[] nums) { 3 | Map f =new HashMap<>(); 4 | Integer [] newNums = new Integer[nums.length]; 5 | 6 | for(int i=0; i{ 12 | if (f.get(n1) != f.get(n2)){ 13 | return f.get(n1)-f.get(n2); 14 | } 15 | else{ 16 | return n2-n1; 17 | } 18 | }); 19 | for (int i = 0; i < nums.length; i++) { 20 | nums[i] = newNums[i]; 21 | } 22 | 23 | return nums; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Day20_FindTheStudentThatWillReplaceTheChalk.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int chalkReplacer(int[] chalk, int k) { 3 | 4 | // worst case 5 | 6 | // int i=0; 7 | // while(i map = new HashMap<>(); 5 | for(int i=0;i0){ 14 | int digit=n%10; 15 | n=n/10; 16 | mapped_n+=base*mapping[digit]; 17 | base*=10; 18 | } 19 | map.put(i,mapped_n); 20 | } 21 | Map nmap = sortByValue(map); 22 | for(int i=0;i