Skip to main content

Posts

Showing posts with the label searching

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...

Kth smallest element (DSA)

Problem Statement :(👈click here for GFG) Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the Kth smallest element in the given array. It is given that all array elements are distinct. Note :-  l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Output : 7 Explanation : 3rd smallest element in the given array is 7. Example 2: Input: N = 5 arr[] = 7 10 4 20 15 K = 4 Output : 15 Explanation : 4th smallest element in the given array is 15. Your Task: You don't have to read input or print anything. Your task is to complete the function kthSmallest() which takes the array arr[], integers l and r denoting the starting and ending index of the array and an integer K as input and returns the Kth smallest element. Expected Time Complexity: O(n) Expected Auxiliary Space: O(log(n)) Constraints: 1 <= N <= 105 1 <= arr[i] <= 105 1 <= K <= N Solution:1 cl...

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...

Missing number in array

Problem statement: (👈click here for GFG) Given an array of size  N-1  such that it only contains distinct integers in the range of  1 to N . Find the missing element. Example 1: Input: N = 5 A[] = {1,2,3,5} Output: 4 Example 2: Input: N = 10 A[] = {6,1,2,8,3,4,7,10,5} Output: 9 Your Task : You don't need to read input or print anything. Complete the function  MissingNumber()  that takes array and N as input parameters and returns the value of the missing number. Expected Time Complexity:  O(N) Expected Auxiliary Space:  O(1) Constraints: 1 ≤ N ≤ 10 6 1 ≤ A[i] ≤ 10 6 Solution:  One approach to solve this problem in O(N) time complexity and O(1) space complexity is to use the mathematical formula to calculate the sum of first N natural numbers and subtract the sum of elements in the given array from it. The result will be the missing element. Algorithm: Initialize a variable named 'expectedSum' to store the sum of first N natural numbers...