Skip to main content

Posts

Showing posts with the label greedy

Full Stack Developer Without Degree: How to Become One

If you're interested in becoming a Full Stack Developer without a degree, we've put together some tips and resources to help you get started. Learn the Fundamentals The first step to becoming a Full Stack Developer is to learn the fundamentals of coding. You can start with HTML, CSS, and JavaScript, which are the building blocks of web development. There are plenty of free resources available online, such as Codecademy and FreeCodeCamp, which offer interactive courses that teach you the basics of web development. Once you have a solid understanding of the basics, you can move on to more advanced topics such as back-end development, databases, and frameworks. You can learn these topics through online courses or by working on personal projects. Build a Portfolio One of the most important things you can do as a Full Stack Developer is to build a portfolio. Your portfolio should showcase your skills and experience and demonstrate your ability to build real-world applications. You c...

Stock buy and sell (DSA)

  Problem Statement :(👈click here for GFG) The cost of stock on each day is given in an array  A [] of size  N . Find all the segments of days on which you buy and sell the stock so that in between those days  for which profit can be generated . Note:   Since there can be multiple solutions ,  the driver code will print 1 if your answer is correct, otherwise, it will return 0. In case there's no profit the driver code will print the string " No Profit " for a correct solution. Example 1: Input: N = 7 A[] = {100,180,260,310,40,535,695} Output: 1 Explanation: One possible solution is (0 3) (4 6) We can buy stock on day 0, and sell it on 3rd day, which will give us maximum profit. Now, we buy stock on day 4 and sell it on day 6. Example 2: Input: N = 5 A[] = {4,2,2,2,4} Output: 1 Explanation: There are multiple possible solutions. one of them is (3 4) We can buy stock on day 3, and sell it on 4th day, which will give us maximum profit. Your Task...

Majority Element (DSA)

Problem statement :(👈click here for GFG) Given an array   A   of   N   elements. Find the majority element in the array. A majority element in an array A of size N is an   element that appears more than N/2 times in the array .   Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function  majorityElement () which returns the majority element in the array. If no majority exists, return -1.   Expected Time Complexity:  O(N). Expected Auxiliary Space:  O(1).   Constraints: 1 ≤ N ≤ 10 7 0 ≤ A i  ≤ 10 6 Solution: Approach: One way to solve this problem is by using the Boyer-Moore majority vote algorithm, which works as follows: Initialize a varia...

Minimum number of jumps (DSA)

Problem statement :(👈click here for GFG) Given an array of   N   integers   arr[]   where each element represents the   maximum   length of the jump that can be made forward from that element. This means if arr[i] = x, then we can jump any distance y such that y ≤ x. Find the minimum number of jumps to reach the end of the array (starting from the first element). If an element is  0 , then you cannot move through that element. Note:  Return -1 if you can't reach the end of the array. Example 1: Input: N = 11 arr[] = {1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9} Output: 3 Explanation: First jump from 1st element to 2nd element with value 3. Now, from here we jump to 5th element with value 9, and from here we will jump to the last. Example 2: Input : N = 6 arr = {1, 4, 3, 2, 6, 7} Output: 2 Explanation: First we jump from the 1st to 2nd element and then jump to the last element. Your task: You don't need to read input or print a...