From 7e52fff3bf2b962ed48895bdc2168f14b214dfa9 Mon Sep 17 00:00:00 2001 From: Arpan Mondal Date: Tue, 26 Apr 2022 18:25:20 +0530 Subject: [PATCH 1/3] Updated functions and arrays --- build-logic/002_functions.md | 20 ++++++++++++++++++++ build-logic/005_arrays.md | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/build-logic/002_functions.md b/build-logic/002_functions.md index 78325b7..a0e55b0 100644 --- a/build-logic/002_functions.md +++ b/build-logic/002_functions.md @@ -25,6 +25,26 @@ **Example:** **Input:** `typeOfTriangle(30, 60, 90)` ––> **Output:** `Scalene Triangle` +1. Given an object `obj`, write a function to invert its `key` and `value` for each entries. Inversion will result in value being used as key and key as value. +**Note:- There will be no repeated values to maintain the uniqueness.** +**Example:** +```javascript + // Input: +obj = { + "name" : "John", + "age" : 51, + "hairColor" : "black", + "eyes" : "round" +} + +// Output: +obj = { + "John" : "name", + "51" : "age", + "black" : "hairColor", + "round" : "eyes" +} +``` ## Medium 1. Given an array, your function should return the length of the array. diff --git a/build-logic/005_arrays.md b/build-logic/005_arrays.md index cace783..0af4432 100644 --- a/build-logic/005_arrays.md +++ b/build-logic/005_arrays.md @@ -15,9 +15,13 @@ 6. Find number of constants and vowels in a string. 7. Shift an array by X to right. - Example [1,2,3,4,5] after shifting to right [5,1,2,3,4] +8. Given an array of numbers, pick any two numbers `a` and `b`, we could get the difference by `Math.abs(a - b)` . Write a function to get the largest difference in the array. ## Advanced 1. Find the sum of two matrix. 1. Display transpose of matrix. Explaination https://www.varsitytutors.com/linear_algebra-help/the-transpose 1. Find Identity matrix. Explanation https://www.varsitytutors.com/hotmath/hotmath_help/topics/identity-matrix + +1. Given an array `arr` with different counts of number we have to find the number with most frequency and return it. +If there are two or more numbers with same most frequency the return the biggest number. \ No newline at end of file From c1e0a17a52c8685befbb35fe2377047e984f523e Mon Sep 17 00:00:00 2001 From: Arpan Mondal Date: Fri, 29 Apr 2022 22:11:24 +0530 Subject: [PATCH 2/3] Update arrays --- build-logic/005_arrays.md | 44 +++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/build-logic/005_arrays.md b/build-logic/005_arrays.md index 0af4432..05d4950 100644 --- a/build-logic/005_arrays.md +++ b/build-logic/005_arrays.md @@ -17,11 +17,47 @@ - Example [1,2,3,4,5] after shifting to right [5,1,2,3,4] 8. Given an array of numbers, pick any two numbers `a` and `b`, we could get the difference by `Math.abs(a - b)` . Write a function to get the largest difference in the array. +9. Given an array and size k, break the array into chunks of k-length and return them as an array. + ```javascript + Input: arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], k = 3 + Output: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]] + ``` +10. Given an array `nums` with length `n` , return the element which occurred at least `n/2` times in the array. + ```javascript + Input: nums = [2,2,1,1,1,2,2] + Output: 2 + ``` +11. Given a string `s`, find the first non-repeating character in it and return its index If it does not exist, return `-1` + ```javascript + Input: s = "neogcamp" + Output: 0 + + Input: s = "nneeooggccaammpp" + Output: -1 + ``` + ## Advanced 1. Find the sum of two matrix. -1. Display transpose of matrix. Explaination https://www.varsitytutors.com/linear_algebra-help/the-transpose -1. Find Identity matrix. Explanation https://www.varsitytutors.com/hotmath/hotmath_help/topics/identity-matrix +2. Display transpose of matrix. Explaination https://www.varsitytutors.com/linear_algebra-help/the-transpose +3. Find Identity matrix. Explanation https://www.varsitytutors.com/hotmath/hotmath_help/topics/identity-matrix -1. Given an array `arr` with different counts of number we have to find the number with most frequency and return it. -If there are two or more numbers with same most frequency the return the biggest number. \ No newline at end of file +4. Given an array `arr` with different counts of number we have to find the number with most frequency and return it. +If there are two or more numbers with same most frequency the return the biggest number. +1. Given an array of integers `nums` and an integer `target`, check if there are two numbers in the array such that they add up to target . Return any one pair that add up to `target` + ```javascript + Input: nums = [3,7,11,15], target = 18 + Output: [3,15] + Explanation : nus[0] + nums[3] = 18 + ``` +1. Given an array `arr` with different counts of number we have to find the number with least frequency and return it. +If there are two or more numbers with same least frequency the return the biggest number. + ```javascript + Input: arr = [2, 2, 2, 3, 3, 3, 4, 4, 4, 2, 5, 5, 5, 6, 6] + Output: 6 + ``` +1. Given an integer array `nums`, move all `0's` to the end of it while maintaining the relative order of the non-zero elements. + ```javascript + Input: nums = [0,2,0,3,12,0] + Output: [2,3,12,0,0,0] + ``` From 7d80fd95a0df298ec092a8f50bdf87789d0d1364 Mon Sep 17 00:00:00 2001 From: Arpan Mondal Date: Fri, 29 Apr 2022 22:15:01 +0530 Subject: [PATCH 3/3] Update questions in strings --- build-logic/004_strings.md | 9 +++++++++ build-logic/005_arrays.md | 8 -------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/build-logic/004_strings.md b/build-logic/004_strings.md index b81ca54..1ffd8bf 100644 --- a/build-logic/004_strings.md +++ b/build-logic/004_strings.md @@ -45,3 +45,12 @@ 1. Write a program to toggle case of each character of the string "good afternoon" (example: "neogcamp" ⇒ "nEoGcAmP" ) 1. Given a string "how was your day?" and a word "how", write a program that removes the occurrence of the specified word from given sentence. ( input: string⇒"programming camp are amazing",word⇒ "programming"; output:" camp are amazing") + +1. Given a string `s`, find the first non-repeating character in it and return its index If it does not exist, return `-1` + ```javascript + Input: s = "neogcamp" + Output: 0 + + Input: s = "nneeooggccaammpp" + Output: -1 + ``` \ No newline at end of file diff --git a/build-logic/005_arrays.md b/build-logic/005_arrays.md index 05d4950..0657154 100644 --- a/build-logic/005_arrays.md +++ b/build-logic/005_arrays.md @@ -27,14 +27,6 @@ Input: nums = [2,2,1,1,1,2,2] Output: 2 ``` -11. Given a string `s`, find the first non-repeating character in it and return its index If it does not exist, return `-1` - ```javascript - Input: s = "neogcamp" - Output: 0 - - Input: s = "nneeooggccaammpp" - Output: -1 - ``` ## Advanced