Posts

Showing posts from November, 2022

Find Players With Zero or One Losses LeetCode

Problem Link: https://leetcode.com/problems/find-players-with-zero-or-one-losses/description/ Solution Link: class Solution {     public List < List < Integer >> findWinners ( int [][] matches ) {         TreeMap <Integer,Integer>map1= new TreeMap < Integer , Integer >();         TreeMap <Integer,Integer>map2= new TreeMap < Integer , Integer >();         for ( int i = 0 ;i< matches . length ;i++){             int a =matches[i][ 0 ];                         if ( map1 . containsKey (a)){                 map1 . put (a, map1 . get (a)+ 1 );             }             else {                 map1 . put (a, 1 );             }...

LCM Triplet Geeks For Geeks

Problem Link: https://practice.geeksforgeeks.org/problems/lcm-triplet1501/1 (It is also the problem of the day for 20-11-2022.) Solution: class Solution {     long lcmTriplets(long N) {         if(N<=2){             return N;         }         else if((N&1)==0){             if(N%3==0){                 N--;                 return N*(N-1)*(N-2);             }             return N*(N-1)*(N-3);         }         return N*(N-1)*(N-2);     } } Time Complexity: O(log n)[GFG Time:2.22] Space Complexity:O(1) Auxiliary Space:O(1) Total Test Cases: 1000105 Approach Used: Here we observe carefully. Then we notice one thing we need to return the multiplication of three numbers a...

Check if all levels of two trees are anagrams or not Geeks For Geeks

Problem Link: https://practice.geeksforgeeks.org/problems/check-if-all-levels-of-two-trees-are-anagrams-or-not/1 (It is also the problem of the day for 19-November-2022) Solution: class Solution {     public static void fun(Node root,ArrayList<Integer>arr){         if(root==null){             return ;         }         else{             Queue<Node>queue=new LinkedList<Node>();             queue.add(root);             arr.add(root.data);             while(!queue.isEmpty()){                 int a=queue.size();                 for(int i=0;i<a;i++){                     Node current=queue.remove();         ...