Posts

Showing posts from January, 2025

DSA Array | Valid Anagram

Problem Statement Write a function that takes two strings, s and t, as input and determines whether they are anagrams of each other. Return true if the two strings are anagrams and false otherwise. An anagram is defined as a string formed by rearranging the characters of another string, using all the original characters exactly once. Example 1: Input: s = "listen", t = "silent" Output: true Explanation: Both strings contain the same characters ('l', 'i', 's', 't', 'e', 'n') in different orders. Example 2: Input: s = "hello", t = "world" Output: false Explanation: The characters in s and t do not match exactly. Code: class Solution { public boolean isAnagram(String s, String t) { Map <Character, Integer> map = new HashMap <> (); int n1 = s.length(); ...

DSA Blind 75 | Problems and solutions

75 DSA problems topicwise Given below is a list of popular DSA problems topicwise with solutions. Arrays Contains duplicate Valid Anagram more to come..

DSA Array | Contains duplicate

Problem Statement You are given an array of integers, nums . Your task is to determine if the array contains any duplicate values. Return: true if any value appears more than once in the array. false if all values in the array are unique. Examples Example 1: Input: nums = [1, 2, 3, 1] Output: true   Explanation: The value 1 appears twice in the array. Example 2: Input: nums = [1, 2, 3, 4] Output: false   Explanation: All values in the array are unique. Code: class Solution { public boolean hasDuplicate(int[] nums) { int n = nums.length; Set set = new HashSet Time complexity:  O(n) Space complexity: O(n)