Skip to main content

Posts

Showing posts with the label Java Solutions

My First Week in India: Expectations vs. Reality

My First Week in India: Expectations vs. Reality My First Week in India: Expectations vs. Reality Arriving in a new country is always a mix of excitement and apprehension. As I embarked on my journey to India, I had a set of expectations based on research, stories, and stereotypes. My first week in India has been a whirlwind of experiences that have both aligned with and diverged from my expectations. Here’s a comparison of what I anticipated versus what I actually encountered. Expectations Warm and Humid Weather: I expected the weather to be consistently warm and humid, as is often depicted in travel blogs and movies. Spicy Food: I anticipated a diet heavily spiced with rich and diverse flavors, given India’s renowned culinary reputation. Cultural Festivities: I was excited to witness vibrant cultural festivals and traditional celebrations throughout the year. ...

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