From c58ecf6b016b05c02f1d50cc7dece69a7ba03d52 Mon Sep 17 00:00:00 2001 From: Manas Ranjan Sahoo Date: Sat, 15 Oct 2022 12:42:46 +0530 Subject: [PATCH 1/6] 2395. Find Subarrays With Equal Sum --- java/2395-Find-Subarrays-With-Equal-Sum.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 java/2395-Find-Subarrays-With-Equal-Sum.java diff --git a/java/2395-Find-Subarrays-With-Equal-Sum.java b/java/2395-Find-Subarrays-With-Equal-Sum.java new file mode 100644 index 0000000..28de6d0 --- /dev/null +++ b/java/2395-Find-Subarrays-With-Equal-Sum.java @@ -0,0 +1,16 @@ +import java.util.Set; +import java.util.HashSet; + +//2395. Find Subarrays With Equal Sum + +class Solution { + public boolean findSubarrays(int[] nums) { + Set set = new HashSet<>(); // To Track previous sum calculated + + for(int i=1; i < nums.length; i++){ + set.add(nums[i] + nums[i-1]); + } + // Check if sum already exist + return set.size() != (nums.length -1); + } +} \ No newline at end of file From ee889bd55119d58659ceb18dcebc2a3139bbc190 Mon Sep 17 00:00:00 2001 From: Manas Ranjan Sahoo Date: Sat, 15 Oct 2022 12:51:46 +0530 Subject: [PATCH 2/6] 387. First Unique Character in a String --- java/387-First-Unique-Character-in-a-String.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 java/387-First-Unique-Character-in-a-String.java diff --git a/java/387-First-Unique-Character-in-a-String.java b/java/387-First-Unique-Character-in-a-String.java new file mode 100644 index 0000000..8fa6d1c --- /dev/null +++ b/java/387-First-Unique-Character-in-a-String.java @@ -0,0 +1,11 @@ +class Solution { + public int firstUniqChar(String s) { + for(int i=0; i< s.length(); i++){ + // If the character is found only once, then indexOf and lastIndexOf will point to same index position. + if(s.indexOf(s.charAt(i)) == s.lastIndexOf(s.charAt(i))){ + return i; + } + } + return -1; + } +} \ No newline at end of file From d128c31b485e1239645c5fcffb6d87f16199e050 Mon Sep 17 00:00:00 2001 From: Manas Ranjan Sahoo Date: Sat, 15 Oct 2022 12:54:40 +0530 Subject: [PATCH 3/6] 1512. Number of Good Pairs --- java/1512-Number-of-Good-Pairs.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 java/1512-Number-of-Good-Pairs.java diff --git a/java/1512-Number-of-Good-Pairs.java b/java/1512-Number-of-Good-Pairs.java new file mode 100644 index 0000000..6b7b24e --- /dev/null +++ b/java/1512-Number-of-Good-Pairs.java @@ -0,0 +1,17 @@ +import java.util.HashMap; +import java.util.Map; + +//1512. Number of Good Pairs +class Solution { + public int numIdenticalPairs(int[] nums) { + int res = 0; + Map count= new HashMap(); + for (int a: nums) + { + int cur=count.getOrDefault(a,0); + res += cur; + count.put(a,cur+1); + } + return res; + } +} \ No newline at end of file From 564839a6387477e589c057d1f5bd9aad68c1fe40 Mon Sep 17 00:00:00 2001 From: Manas Ranjan Sahoo Date: Sat, 15 Oct 2022 12:56:26 +0530 Subject: [PATCH 4/6] 2418. Sort the People --- java/2418-Sort-the-People.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 java/2418-Sort-the-People.java diff --git a/java/2418-Sort-the-People.java b/java/2418-Sort-the-People.java new file mode 100644 index 0000000..608709a --- /dev/null +++ b/java/2418-Sort-the-People.java @@ -0,0 +1,20 @@ +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +class Solution { + public String[] sortPeople(String[] names, int[] heights) { + Map map = new HashMap<>(); + for (int i = 0; i < names.length; i++) { + map.put(heights[i], names[i]); + } + Arrays.sort(heights); + String[] result = new String[heights.length]; + int index = 0; + for (int i = heights.length - 1; i >= 0; i--) { + result[index] = map.get(heights[i]); + index++; + } + return result; + } +} \ No newline at end of file From a738ceef5aec74eef55df55f2d948bb0c4c43037 Mon Sep 17 00:00:00 2001 From: Manas Ranjan Sahoo Date: Sat, 15 Oct 2022 13:00:33 +0530 Subject: [PATCH 5/6] Add my name in PARTICIPANTS.md File --- PARTICIPANTS.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/PARTICIPANTS.md b/PARTICIPANTS.md index 5a2e2f4..ddeb4cb 100644 --- a/PARTICIPANTS.md +++ b/PARTICIPANTS.md @@ -1,4 +1,3 @@ -

Hi šŸ‘‹, Welcome Contributers!!

@@ -8,6 +7,7 @@

HacktoberFest 2022 contributers details

--- + ### Connect with me: @@ -20,6 +20,7 @@ --- --- + ### Connect with me: @@ -41,6 +42,7 @@ - šŸ”­ Connect with me: **[Harshdev625](https://github.com/Harshdev625)** --- + ### Connect with me: @@ -51,6 +53,7 @@ - šŸ”­ Connect with me: **[manavagr1108](https://github.com/manavagr1108)** --- + ### Connect with me: @@ -61,6 +64,7 @@ - šŸ”­ Connect with me: **[rivubanerjee04](https://github.com/rivubanerjee04)** --- + ### Connect with me: @@ -71,6 +75,7 @@ - šŸ”­ Connect with me: **[rivubanerjee04](https://github.com/sarapapa-sp)** --- + ### Connect with me: @@ -90,6 +95,7 @@ - šŸ”­ Connect with me: **[SwastikMo](https://github.com/SwastikMo)** --- + ### Connect with me: @@ -100,11 +106,12 @@ - šŸ”­ Connect with me: **[Prakhar Khandelwal](https://github.com/tigllon)** --- + ### Connect with me: -- šŸ‘Øā€šŸ’» My name is *r** +- šŸ‘Øā€šŸ’» My name is \*r\*\* - 🌱 I’m a . - šŸ“« Reach me: **** - šŸ”­ Connect with me: **[](https://github.com/)** @@ -132,6 +139,7 @@ - šŸ”­ Connect with me: **[Vikash0122](https://github.com/Vikash0122))** --- + ### Connect with me: @@ -142,3 +150,14 @@ - šŸ”­ Connect with me: **[Piyushjar](https://github.com/piyushjar))** --- + +### Connect with me: + +Manas Sahoo + +- šŸ‘Øā€šŸ’» My name is **Manas Sahoo** +- 🌱 I’m a Senior Frontend Developer. +- šŸ“« Reach me: **manas_sahoo@outlook.com** +- šŸ”­ Connect with me: **[Manas Sahoo](https://github.com/manassahoo-dev))** + +--- From e8549a11e13291876e1185a5ea90aa9ea0f4ff2b Mon Sep 17 00:00:00 2001 From: Jagroop Singh Date: Sun, 16 Oct 2022 17:34:45 +0530 Subject: [PATCH 6/6] Dutch National Flag Problem --- javascript/DutchNationalFlag-Problem.js | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 javascript/DutchNationalFlag-Problem.js diff --git a/javascript/DutchNationalFlag-Problem.js b/javascript/DutchNationalFlag-Problem.js new file mode 100644 index 0000000..bc1ecc7 --- /dev/null +++ b/javascript/DutchNationalFlag-Problem.js @@ -0,0 +1,41 @@ +// Given an array A[] consisting of only 0s, 1s, and 2s. The task is to write a function that sorts +// the given array. The functions should put all 0s first, then all 1s and all 2s in last. +// This Problem is also known as Dutch National Flag. + +// First Sol --> Using Sort +// Second Sol ---> Count Sort + +//Efficient Solution + +function DutchNationalFlagSort(array){ + + let low =0; + let mid = 0; + let high = array.length -1; + let temp =0; + + while(mid <=high){ + + if(array[mid] == 0){ + temp = array[low] + array[low] = array[mid] + array[mid] = temp + + low++; + mid++; + }else if(array[mid] == 1){ + mid++; + }else{ + temp = array[mid] + array[mid] = array[high] + array[high] = temp + + high-- + } + } + + return array; + } + + + console.log(DutchNationalFlagSort([0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1 ])); \ No newline at end of file