Skip to main content

Posts

33. Search in Rotated Sorted Array

 33. Search in Rotated Sorted Array 📄 Problem Statement : There is an integer array nums sorted in ascending order (with distinct values). Before being passed to your function, nums may be rotated at an unknown pivot index k (where 1 <= k < nums.length ) such that the array becomes [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] . You are given the array nums after the rotation and an integer target . Your task is to return the index of the target if it exists in nums , or return -1 if it does not exist. You must solve it in O(log n) time. 📚 Examples : Example 1 : Input: nums = [4,5,6,7,0,1,2], target = 0 Output: 4 Example 2 : Input: nums = [4,5,6,7,0,1,2], target = 3 Output: -1 Example 3 : Input: nums = [1], target = 0 Output: -1 📜 Constraints : 1 <= nums.length <= 5000 -10⁴ <= nums[i] <= 10⁴ All values of nums are unique . nums is a sorted array, possibly rotated . -10⁴ <= target <= 10⁴ ...
Recent posts

53. Maximum Subarray | Kadane’s Algorithm

53. Maximum Subarray  Medium Topics: Array, Dynamic Programming 💬 Problem Statement: Given an integer array nums , find the subarray with the largest sum , and return its sum. 🧪 Examples: Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: The subarray [4,-1,2,1] has the largest sum 6. Example 2: Input: nums = [1] Output: 1 Explanation: The subarray [1] has the largest sum 1. Example 3: Input: nums = [5,4,-1,7,8] Output: 23 Explanation: The subarray [5,4,-1,7,8] has the largest sum 23. 🔒 Constraints: 1 <= nums.length <= 10⁵ -10⁴ <= nums[i] <= 10⁴ 🧠 Approach 1: Kadane's Algorithm (O(n) Time) Kadane’s Algorithm helps you find the maximum sum of a contiguous subarray in just one pass. 👉 Intuition: We move through the array and: Keep adding elements to a running sum ( maxEndingHere ) If maxEndingHere becomes negative, we reset it to 0 Track the maximum seen so far in maxSoFar   MY solution, 🪄 Java Code:   ...

Chocolate Distribution Problem

Chocolate Distribution Problem Given an array  arr[]  of positive integers, where each value represents the number of chocolates in a packet. Each packet can have a variable number of chocolates. There are  m  students, the task is to distribute chocolate packets among  m  students such that -       i. Each student gets  exactly  one packet.      ii. The difference between maximum number of chocolates given to a student and minimum number of chocolates given to a student is minimum and return that minimum possible difference. Examples: Input: arr = [3, 4, 1, 9, 56, 7, 9, 12], m = 5 Output: 6 Explanation: The minimum difference between maximum chocolates and minimum chocolates is 9 - 3 = 6 by choosing following m packets :[3, 4, 9, 7, 9]. Input: arr = [7, 3, 2, 4, 9, 12, 56], m = 3 Output: 2 Explanation: The minimum difference between maximum chocolates and minimum chocolates is 4 - 2 = 2 by choosing following m packe...

217. Contains Duplicate

217. Contains Duplicate Difficulty: Easy Problem Statement Given an integer array nums , return true if any value appears at least twice in the array, and return false if every element is distinct . Example 1: Input: nums = [1, 2, 3, 1] Output: true Explanation: The element 1 appears more than once (at indices 0 and 3). Example 2: Input: nums = [1, 2, 3, 4] Output: false Explanation: All elements are unique. Example 3: Input: nums = [1, 1, 1, 3, 3, 4, 3, 2, 4, 2] Output: true Explanation: Several elements appear multiple times: 1 , 3 , 4 , and 2 . Constraints: 1 <= nums.length <= 10⁵ -10⁹ <= nums[i] <= 10⁹ Solution:   import java.util.Arrays; class Solution {     public boolean containsDuplicate ( int [] nums ) {         Arrays . sort (nums); // Sort the array         for ( int i = 1 ; i < nums . length ; i++) {             if (nums[i]...

How to Crack College Placements: A Complete Guide to Projects, Interviews, and Success

How to Crack College Placements: A Complete Guide to Projects, Interviews, and Success How to Crack College Placements: A Complete Guide to Projects, Interviews, and Success Welcome to the first episode of The Mali Show ! If you're a student preparing for college placements , you're probably feeling both excited and nervous. Landing that dream job or internship is a big deal, but with the right approach, cracking campus placements doesn’t have to be a stressful experience. In this blog post, we’ll break down everything you need to know about how to crack college placements , from selecting the perfect placement projects to preparing for those nerve-wracking interviews . With these tips, you’ll be one step closer to success. 1. How to Crack College Placements: The Basics When it comes to college placements , understanding the entire process is key. Every college has its own str...

How to Improve Your Communication Skills: Essential Tips for Effective Interaction

How to Improve Your Communication Skills: Essential Tips for Effective Interaction How to Improve Your Communication Skills: Essential Tips for Effective Interaction Effective communication is an essential skill that influences every aspect of our lives, from personal relationships to professional success. Improving your communication skills can lead to better interactions, clearer understanding, and more meaningful connections. This comprehensive guide provides detailed strategies and practical tips to help you enhance your communication abilities. 1. Listen Actively Active listening is the foundation of effective communication. It involves fully concentrating, understanding, responding, and then remembering what is being said. Here are some ways to practice active listening: Give Full Attention: Avoid distractions such as checking your phone or thinking about what you'll say next. Focus entirely on the speaker. ...

Mohan babu university Placements | Placement in Mohan babu university | MBU Tirupati | Dim vlogs

Jobs and Placement at Mohan Babu University Jobs and Placement at Mohan Babu University Mohan Babu University (MBU) is well-known for offering excellent education and career opportunities to its students. The university has a dedicated placement cell that works hard to ensure that students get placed in top companies across India and abroad. MBU has built strong relationships with recruiters from various industries, helping students start their careers with good job offers. Why Choose Mohan Babu University for Placements? At Mohan Babu University, students not only receive quality education but also have access to a strong placement network. The university’s placement cell works throughout the year to help students prepare for interviews, develop soft skills, and connect with leading companies. This is one of the key reasons why students at MBU have high placement success rates. Placement Statistics at Mohan Babu Univ...