Saturday, June 5, 2021

LEETCODE JUNE 2021 DAILY CODING CHALLENGE

 LEETCODE JUNE 2021 DAILY CODING CHALLENGE


JUNE 1



JUNE 2



JUNE 3



JUNE 4


JUNE 5

Maximum Performance of a Team

LINK

You are given two integers n and k and two integer arrays speed and efficiency both of length n. There are n engineers numbered from 1 to n. speed[i] and efficiency[i] represent the speed and efficiency of the ith engineer respectively.

Choose at most k different engineers out of the n engineers to form a team with the maximum performance.

The performance of a team is the sum of their engineers' speeds multiplied by the minimum efficiency among their engineers.

Return the maximum performance of this team. Since the answer can be a huge number, return it modulo 109 + 7.

 

const int mod = 1e9 + 7;

    int maxPerformance(int n, vector<int>& speed, vector<int>& efficiency, int k) {

        vector<pair<int, int>>ord;

        

        for(int i = 0; i < n; i++){

            ord.push_back({efficiency[i], speed[i]});

        }

        sort(ord.rbegin(), ord.rend());

        priority_queue<int>speedPq;

        

        long totalSpeed = 0, res = 0;

        

        for(auto& p : ord){

            int spd = p.second;

            speedPq.push(-spd);

            if(speedPq.size() <= k)

                totalSpeed += spd;

            else{

                totalSpeed += spd + speedPq.top();

                speedPq.pop();

            }

            res = max(res, totalSpeed*p.first);

        }

        return res% mod;

    }

Sunday, May 23, 2021

HACKERRANK - INTERVIEW PREP KIT- SOLUTIONS IN CPP

HACKERRANK INTERVIEW PREP KIT SOLUTIONS-

* WARM-UP CHALLEGES-


COUNTING VALLEYS

PROBLEM



* DATA STRUCTURES


ARRAY


LINKED LIST


STACK


QUEUE



 HACKERRANK - CRACKING THE CODING INTERVIEW TUTORIALS SOLUTIONS IN CPP


HASH TABLES - RANSOM NOTE

PROBLEM

Complete the checkMagazine function in the editor below. It must print  if the note can be formed using the magazine, or .

checkMagazine has the following parameters:

  • string magazine[m]: the words in the magazine
  • string note[n]: the words in the ransom note

Prints

  • string: either  or , no return value is expected

Input Format

The first line contains two space-separated integers,  and , the numbers of words in the  and the , respectively.
The second line contains  space-separated strings, each .
The third line contains  space-separated strings, each .

Constraints

  • .
  • Each word consists of English alphabetic letters (i.e.,  to  and  to ).

Sample Input 0

6 4
give me one grand today night
give one grand today

Sample Output 0

Yes
MY SOLUTION-
void checkMagazine(vector<string> magazine, vector<string> note) {
    //Simple finding in the string magazine - passes some test cases
    // for(int i = 0; i < note.size();){
    //     if(find(magazine.begin()+i, magazine.end(), note[i]) != magazine.end())
    //         i++;
    //     else{
    //         cout << "No" <<"\n";
    //         return;
    //     }    
    // }
    // cout << "Yes" <<"\n";
//Hashing in Strings
    unordered_map<string, int>words;
    
    for(auto &it: magazine){ //N words
        words[it]++;
    }
    
    for(auto &it : note){// M words
        if(words[it]> 0){
            words[it]--;
        }
        else{
            cout << "No" <<"\n";
            return;
        }
    }
    cout << "Yes" <<"\n";
    return;
}
TC = O(N+M)

Thursday, May 20, 2021

GENERAL CODING TIPS

 BEGINNER PROGRAMMING TIPS - ANUJ BHAIYA

* START WITH A GOAL-

WORK BACKWARDS FROM A BIG GOAL

* FIRST PROGRAMMING LANGUAGE-

PYTHON

LEARNPYTHON.ORG, FREECODECAMP

YOUTUBE

UDEMY COURSES

1 TUTORIAL - BEST ONE - TAKE AND START AND COMPLETE IT

* BEGINNER - DON'T FOCUS MUCH ON DETAILS

* MAKE A ROUTINE FOR CODING - 

DAILY 2 HR - DSA

DAILY 2 HR- DEV

CONSISTENCY

DON'T GIVE UP

* MAKE PROJECTS WHILE LEARNING

UNDERSTAND MEANING OF ALL THINGS 

IMPLEMENT 1ST

THEN MAKE SOME IMPROVEMENTS

* AFTER PROGRAMMING LANGUAGE - MOVE TO DSA

FOR DSA -  USE CPP OR JAVA

LEARN IMP DS AND ALGORITHMS

LEARN CONCEPT - AT LEAST PRACTICE 10 Q

LEETCODE / HACKERRANK - PRACTICE DSA

* DEVELOPMENT - PROJECTS

* ITS OKAY TO TAKE TIME TO LEARN A NEW LANGUAGE AND TECHNOLOGY

* ITS OKAY TO SEE EDITORIAL

* ITS OKAY TO REACH OUT FOR HELP

HELP OTHERS ALSO IF U KNOW

* DON'T GIVE UP

* 1 THING AT A TIME

* PROGRAMMING LANGUAGE + DSA - DAILY IMP 

THEN DEV + PROJECTS


HOW ANUJ BHAIYA BECAME SELF TAUGHT PROGRAMMER? - ANUJ BHAIYA

*HAVE A BIG GOAL - FOR MOTIVATION -

*DON'T GIVE UP

*ANY LANGUAGE - 

THEORY =  5%

PRACTICAL = PROJECTS = 95%

*OBJECT ORIENTED PROGRAMMING LANGUAGE- CPP/ JAVA

HE LEARNT JAVA - BOOK + HAY OF PROGRAMMING BOOK

DSA STUDY STARTED

CODECHEF - LESS BEGINNER-FRIENDLY

HACKERRANK, HACKEREARTH - PRACTICE + CONTESTS

ANDROID DEVELOPMENT-

UDEMY - FREE COURSE

YOUTUBE PLAYLIST 

HIS ANDROID DEV PLAYLIST

TO LEARN NEW THING -

MAKE A GOAL TO MAKE PROJECT AND THEN LEARN THINGS TO MAKE THAT PROJECT

* DSA - FOLLOW A STRUCTURE

INTERVIEW BIT

BREADTH FIRST APPROACH RATHER THAN DEPTH FIRST

* LEARN A FRAMEWORK/ TECH

LEARN JUST ENOUGH

MAKE PROJECTS

IMPLEMENT THINGS

IMPLEMENTATION IS THE KEY

MAKE UR TODAY BETTER THAN YESTERDAY










* 

LEETCODE JUNE 2021 DAILY CODING CHALLENGE

 LEETCODE JUNE 2021 DAILY CODING CHALLENGE JUNE 1 JUNE 2 JUNE 3 JUNE 4 JUNE 5 Maximum Performance of a Team LINK You are given two integers ...