├── HackerEarth └── README.md ├── SQL ├── README.md ├── 182-Duplicate_Emails ├── 584-Find_Customer_Referee ├── 175-Combine_Two_Tables ├── 181-Employees_Earning_More ├── 196-Delete_Duplicate_Emails.sql └── 183-Customers_Who_Never_Order.sql ├── Geeks For Geeks ├── README.md ├── Bit Manipulation │ ├── README.md │ └── 001-FindOddOrEven.java ├── DSA 450 │ ├── 006-Cyclically_Rotate_an_Array_by_One.java │ ├── 005-Union_Of_Two_Arrays.java │ ├── 002-Finding_Kth_Min_Element.java │ ├── 004-Move_all_negative_elements_end.java │ ├── 008-Minimize_the_Heights_II.java │ ├── 003-Sort_an_array_of_0_1_2.java │ └── 007-Kadane_Algorithm.java ├── Arrays │ ├── Searching │ │ ├── 101-Linear_Search.cpp │ │ ├── 103-Recursive_Sort.cpp │ │ └── 102-Binary_Search.cpp │ ├── Rotation │ │ └── 101-Array_Rotation.cpp │ ├── 001-Find_the_repeating_and_the_missing.java │ ├── 002-Leaders_In_Array.java │ └── 50 Top Problems │ │ └── 001-PeakElement.java ├── Mathematical │ └── README.md └── Linked List │ └── 002-Linked_List_Traversal.cpp ├── BigFrontEnd ├── DSA │ ├── 0153_Minimum_Rotated_SubArray.js │ ├── 0242_Valid_Anagram.js │ ├── 0151_Reverse_Words_In_String.js │ ├── 0104_Maximum_Depth_of_Binary_Tree.js │ ├── 0371_Sum_of_Two_Integers.js │ ├── Must Do DSA │ │ ├── Fibonacci.js │ │ ├── Factorial.js │ │ ├── LinearSearch.js │ │ ├── RecursiveFactorial.js │ │ ├── RecursiveFibonacci.js │ │ ├── Prime_Number_Check.js │ │ ├── BubbleSort.js │ │ ├── SelectionSort.js │ │ ├── BinarySearch.js │ │ └── Power_Of_Two_Check.js │ ├── 0053_Max_SubArray.js │ ├── 0070_Climbing_Stairs.js │ ├── 0226_Invert_Binary_Tree.js │ ├── 0509_Fibonacci_Number.js │ ├── 0100_Same_Tree.js │ ├── 0141_Linked_List_Cycle.js │ ├── 0206_Reverse_Linked_List.js │ ├── 1796_Second_Largest_Digit_String.js │ ├── 0098_Validate_Binary_Search_Tree.js │ ├── 0049_Group_Anagram.js │ ├── Interview Exp │ │ ├── MoveZeroes.js │ │ ├── NonRepeatingChar.js │ │ ├── CompressString.js │ │ └── Flatten_Obj.js │ ├── 0235_Lowest_Common_Ancestor_Binary_Search_Tree.js │ ├── 0152_Maximum_Product_Subarray.js │ ├── 0704_Binary_Search.js │ ├── 0020_Valid_Parentheses.js │ ├── 0011_Container_with_Most_Water.js │ ├── 0383_Ransom_Note.js │ ├── 0733_Flood_Fill.js │ ├── 0003_Longest_Substring_Without_Repeating_Characters.js │ ├── 0278_First_Bad_Version.js │ ├── 0021_Merge_Two_Sorted_Lists.js │ ├── 0110_Balanced_Binary_Tree.js │ ├── 0019_Remove_Nth_Node_From_End_List.js │ ├── 0409_Longest_Palindrome.js │ ├── 102_Binary_Tree_Level_Order_Traversal.js │ ├── 0033_Search_in_Sorted_Array.js │ ├── 0015_3Sum.js │ ├── 0023_Merge_k_Sorted_Lists.js │ ├── 0232_Implement_Queue_using_Stacks.js │ ├── 0016_3Sum.js │ ├── 0784_Letter_Case_Permutation.js │ ├── 0121_Best_Time_To_Buy_Stock.js │ ├── 0217_Contains_Duplicates.js │ └── 0316_Remove_Duplicate_Letters.js ├── BFE │ └── JS │ │ ├── 006_Implemement_Basic_Debounce.js │ │ ├── 0001_implement_curry.js │ │ ├── 0023_create_sum.js │ │ └── 0003_implement_Array.prototype.flat.js ├── JS Interview Concept Snippets │ ├── Closure.js │ ├── Callable_Function.js │ ├── Event_Delegration.js │ ├── Map_Polyfill.js │ ├── Filter_Polyfill.js │ ├── Reduce_Polyfill.js │ ├── ArrayFlat.js │ ├── PromiseRace.js │ ├── Currying.js │ ├── Event_Bubbling.js │ ├── Prototypical_Inheritance.js │ ├── Debouncing.js │ ├── PromiseAllPolyfill.js │ ├── Function_Binding.js │ └── PromiseAllSettledPolyfill.js └── React JS Concept Snippets │ └── react.memo.jsx ├── LeetCode ├── 009-Palindrome_Number.py ├── 136-Single_Number.cpp ├── 389-Find_The_Difference.java ├── 1304-Find_N_Unique_Integers_Sum_up_Zero.java ├── 007-Reverse_Integer.py ├── 217-Contains_Duplicate.java ├── 001-Two_Sum.py ├── 771-Jewels_and_Stones.java ├── 053-Maximum_Subarray.java ├── 206-Reverse_Linked_List.java ├── 014-Longest_Common_Prefix.py ├── 038-Count_And_Say.py ├── 344-Reverse_String.java ├── 617-Merge_Two_Binary_Trees.java ├── README.md ├── 520-Detect_Capital.java ├── 557-Reverse_Words_in_a_String_III.java ├── 066-Plus_One.java ├── 287-Find_the_Duplicate_Number.java ├── 050-Pow_x_ n.java ├── 242-Valid_Anagram.java ├── 876-Middle_Of_the_Linked_List.java ├── 189-Rotate_Array.java ├── 169-Majority_Element.java ├── 724-Find_Pivot_Index.java ├── 019-Remove_Nth_Node_From_End.java ├── 035-Search_Insert_Position.java ├── 1047-Remove_All_Adjacent_Duplicates_In_String.java ├── 278-First_Bad_Version.java ├── 118-Pascal_Triangle.java ├── 283-Move_Zeroes.java ├── 125-Valid_Palindrom.java ├── 203-Remove_Linked_List_Elements.java ├── 116-Populating_Next_Right_Pointers_in_Each_Node.java ├── 167-Two_Sum_II.java ├── 011-Container_With_Most_Water.java ├── 704-Binary_Search.java ├── 031-Next_Permutation.java ├── 496-Next_Greater_Element_I.java ├── 142-Linked_List_Cycle_II.java ├── 067-Add_Binary.java ├── 349-Intersection_Of_Two_Arrays.java ├── 394-Decode_String.java ├── 048-Rotate_Image.java ├── 2129-Capitalize_The_Title.java ├── 003-Longest_Substring_Without_Repeating_Characters.java ├── 387-First_Unique_Character_in_a_String.java ├── 733-Flood_Fill.java ├── 73-Set_Matrix_Zeroes.java ├── 141-Linked_List_Cycle.java ├── 002-Add_Two_Numbers.java ├── 021-Merge_Two_Sorted_Lists.java ├── 020-Valid_Parentheses.java ├── 567-Permutation_in_String.java ├── 075-Sort_Colors.java ├── 680-Valid_Palindrome_II.java ├── 695-Max_Area_of_Island.java ├── 657-Robot_Return_To_Origin.java └── 013-3Sum.java ├── HackerRank ├── JAVA │ ├── WelcomeToJava.java │ ├── JavaLoops1.java │ ├── JavaStdinAndStdoutI.java │ ├── JavaStdinAndStdoutII.java │ ├── JavaOutputFormatting.java │ ├── JavaLoopsII.java │ ├── JavaIfElse.java │ └── JavaDatatypes.java ├── README.md └── Problem Solving │ ├── 108-A_very_big_sum.py │ ├── 111-Staircase.py │ ├── 102-Drawing_Book.cpp │ ├── 112-Mini_Max_Sum.py │ ├── 107-Compare_the_Triplets.py │ ├── 106-Simple_Array_Sum.py │ ├── 104-Designer_PDF_Viewer.cpp │ ├── 113-Birthday_Cake_Candles.py │ ├── 110-Plus_Minus.py │ ├── 109-Diagonal_Difference.py │ ├── 105-Utopian_Tree.cpp │ ├── 103-Cats_and_a_Mouse.cpp │ └── 101-Migratory_Birds.cpp ├── React Machine Coding ├── Product_Cart_Publicis_Sapient │ ├── components │ │ ├── atoms │ │ │ ├── Image.js │ │ │ ├── Typography.js │ │ │ └── Button.js │ │ ├── templates │ │ │ └── CartLayout.js │ │ ├── molecules │ │ │ └── ProductCard.js │ │ └── organisms │ │ │ └── CartList.js │ ├── App.js │ ├── pages │ │ └── CartPage.js │ └── services │ │ └── api.js ├── Todo │ ├── style.css │ └── AddTodo.js ├── Stop Watch │ ├── Button.js │ └── styles.css ├── Redux Ecommerce Store │ ├── pages │ │ └── ProductListing.jsx │ ├── store │ │ └── store.js │ ├── main.jsx │ └── App.jsx ├── Debounced Search │ └── App.tsx ├── HOC │ └── Product Fetch │ │ ├── App.js │ │ └── ProductListing.js ├── Star Rating │ ├── style.css │ ├── App.js │ └── StarRating.js ├── OTP Login │ └── styles.css ├── File Manager │ ├── App.jsx │ ├── components │ │ └── Folder.js │ └── data │ │ └── folderInfo.json ├── Custom Hook │ ├── useToggle │ │ ├── useToggle.js │ │ └── TogglePage.js │ ├── customHook.js │ ├── useDebounce │ │ ├── useDebounce.js │ │ └── App.js │ ├── useWindowSize │ │ └── useWindowSize.js │ ├── useLocalStorage │ │ ├── useLocalStorage.js │ │ └── App.js │ ├── useIntersectionObserver │ │ ├── useIntersectionObserver.js │ │ └── App.js │ ├── useFetch │ │ ├── App.js │ │ └── useFetch.js │ ├── React Hooks Polyfills │ │ ├── useEffect │ │ │ ├── App.js │ │ │ └── useCustomEffect.js │ │ └── useMemo │ │ │ ├── App.js │ │ │ └── useCustomMemo.js │ └── Toggle.js ├── JS Machine Coding │ ├── Tabs │ │ ├── index.html │ │ └── styles.css │ ├── Search Typehead │ │ └── index.html │ ├── Counter │ │ ├── index.html │ │ └── script.js │ ├── Todo Application │ │ └── index.html │ └── Stop Watch │ │ ├── index.html │ │ └── script.js ├── Pop Up │ ├── Pop.js │ ├── styles.css │ └── PopUp.js ├── Progress Bar │ ├── App.js │ ├── style.css │ └── ProgressBar.js ├── useContext │ ├── ThemeContext.js │ ├── App.js │ └── ThemeToggler.js ├── BreadCrumb Menu │ ├── styles.css │ ├── pages │ │ ├── product-detail.js │ │ ├── product-listing.js │ │ └── home.js │ ├── components │ │ └── BreadCrumb.js │ └── App.js ├── Pokedex │ └── styles.css ├── Grid Lights │ └── styles.css ├── Infinite Scrolling │ └── InfiniteScrolling.js ├── Stop Watch - useRef │ └── App.js └── Pagination │ └── Style.css ├── CodeForces ├── B-Lovely_Palindromes.java ├── A-Digits_Sum.java ├── A-String_Task.cpp ├── B-Teams_Forming.java ├── B-CopyCopyCopyCopyCopy.java ├── A-Watermelon.java ├── A-Way_Too_Long_Words.java ├── A-PolycarpAndCoins.java ├── B-Mahmoud_and_a_Triangle.java ├── A-Cards_Of_Friends.java ├── B-Bad_Prices.java ├── A-Odd_Set.java ├── A-Contest_Start.java └── B-Social_Network.java ├── Daily Bytes ├── 008-Jewels_and_Stones.java ├── 009-Detect_Capital.java ├── 002-Valid_Palindrome.java ├── README.md ├── 005-Add_Binary.java ├── 004-Correct_Capitalization.java ├── 007-Valid_Palindrome_II.java ├── 001-Reverse String.java ├── 003-Vacuum_Cleaner_Route.java ├── 006-Robot_Return_To_Origin.java └── 010-Replace_0_with_5.java ├── Product_Prep_2024 └── LeetCode │ ├── 0122_Best_Time_Buy_Sell_Stock_II.java │ ├── 0058_Length_Of_Last_Word.java │ ├── 0026_Remove_Duplicates_Sorted_Array.java │ ├── 0080_Remove_Duplicates_Sorted_Array_II.java │ ├── 0392_Is_Subsequence.java │ ├── 0125_Valid_Palindrome.java │ ├── 0151_Reverse_Words_String.java │ ├── 0121_Best_Time_Buy_Sell_Stock.java │ ├── 0001_Two_Sum.java │ ├── 0169_Majority_Element.java │ ├── 0088_Merge_Sorted_Array.java │ ├── 0028_Find_Index_First_Occurrence_String.java │ ├── 0014_Longest_Common_Prefix.java │ ├── 0167_Two_Sum_II_Input_Array_Sorted.java │ └── 0189_Rotate_Array.java ├── DSA SHEET Solution ├── 215-Kth_Max_Element.java ├── 344-Reverse_String.java ├── GFG-Move_All_Negative_Elements_to_End.java └── 075-Sort_Colors.java ├── Dot Net Repository └── DSA C# │ ├── ReverseString.cs │ ├── CheckPrimeNumber.cs │ ├── CheckPalindrome.cs │ └── FactorialUsingRecursion.cs ├── Weekly-DSA └── Week2 │ └── README.md └── CodingNinza └── Problem of the Day └── 02_Jan-PushElementToStack.java /HackerEarth/README.md: -------------------------------------------------------------------------------- 1 | # Hacker Earth🌍 2 | -------------------------------------------------------------------------------- /SQL/README.md: -------------------------------------------------------------------------------- 1 |

SQL Learning

2 | -------------------------------------------------------------------------------- /SQL/182-Duplicate_Emails: -------------------------------------------------------------------------------- 1 | SELECT email 2 | FROM Person 3 | GROUP BY email 4 | HAVING COUNT(DISTINCT id) > 1 -------------------------------------------------------------------------------- /Geeks For Geeks/README.md: -------------------------------------------------------------------------------- 1 | # Geeks For Geeks 2 | 3 | ### Array Problems 4 | 5 | ### Linked List Problems -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0153_Minimum_Rotated_SubArray.js: -------------------------------------------------------------------------------- 1 | var findMin = function(nums) { 2 | return Math.min(...nums) 3 | }; -------------------------------------------------------------------------------- /SQL/584-Find_Customer_Referee: -------------------------------------------------------------------------------- 1 | SELECT name 2 | FROM Customer 3 | WHERE referee_id <> 2 4 | OR referee_id IS NULL 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /LeetCode/009-Palindrome_Number.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPalindrome(self, x: int) -> bool: 3 | s = str(x) 4 | return s == s[::-1] -------------------------------------------------------------------------------- /SQL/175-Combine_Two_Tables: -------------------------------------------------------------------------------- 1 | SELECT p.firstName, p.lastName, a.city, a.state 2 | FROM Person p 3 | LEFT JOIN Address a 4 | ON p.personId = a.personId -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0242_Valid_Anagram.js: -------------------------------------------------------------------------------- 1 | var isAnagram = function(s, t) { 2 | return s.split('').sort().join('') === t.split('').sort().join('') 3 | }; -------------------------------------------------------------------------------- /SQL/181-Employees_Earning_More: -------------------------------------------------------------------------------- 1 | SELECT e1.name AS Employee 2 | FROM Employee e1 3 | LEFT JOIN Employee e2 4 | ON e1.managerId = e2.id 5 | WHERE e1.salary > e2.salary 6 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0151_Reverse_Words_In_String.js: -------------------------------------------------------------------------------- 1 | var reverseWords = function(s) { 2 | let words = s.trim().split(/\s+/) 3 | return words.reverse().join(' ') 4 | 5 | } -------------------------------------------------------------------------------- /SQL/196-Delete_Duplicate_Emails.sql: -------------------------------------------------------------------------------- 1 | with cte as 2 | (select email, min(id) as id_to_keep 3 | from Person 4 | group by email) 5 | 6 | delete from Person 7 | where id not in (select id_to_keep from cte) -------------------------------------------------------------------------------- /LeetCode/136-Single_Number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int singleNumber(vector& nums) { 4 | return accumulate(nums.cbegin(), nums.cend(),0, std::bit_xor()); 5 | } 6 | }; -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0104_Maximum_Depth_of_Binary_Tree.js: -------------------------------------------------------------------------------- 1 | var maxDepth = function(root) { 2 | if(!root) { 3 | return 0 4 | } 5 | 6 | return 1 + Math.max(maxDepth(root.left), maxDepth(root.right)) 7 | }; -------------------------------------------------------------------------------- /HackerRank/JAVA/WelcomeToJava.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args) { 4 | System.out.println("Hello, World."); 5 | System.out.println("Hello, Java."); 6 | } 7 | } -------------------------------------------------------------------------------- /React Machine Coding/Product_Cart_Publicis_Sapient/components/atoms/Image.js: -------------------------------------------------------------------------------- 1 | const Image = ({ src, alt }) => ( 2 | {alt} 3 | ); 4 | 5 | export default Image; 6 | -------------------------------------------------------------------------------- /Geeks For Geeks/Bit Manipulation/README.md: -------------------------------------------------------------------------------- 1 | ## Bit Manipulation 2 | 3 | [Bit Manipulation: Interview Questions and Practice Problems](https://medium.com/techie-delight/bit-manipulation-interview-questions-and-practice-problems-27c0e71412e7) -------------------------------------------------------------------------------- /React Machine Coding/Todo/style.css: -------------------------------------------------------------------------------- 1 | .todo { 2 | margin: auto; 3 | text-align: center; 4 | } 5 | 6 | .todo_item { 7 | display: flex; 8 | } 9 | 10 | .todo_name { 11 | margin-right: 10px; 12 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0371_Sum_of_Two_Integers.js: -------------------------------------------------------------------------------- 1 | var getSum = function(a, b) { 2 | let carry 3 | 4 | while(b!==0) { 5 | carry = a&b 6 | a = a^b 7 | b = carry << 1 8 | } 9 | 10 | return a 11 | }; 12 | -------------------------------------------------------------------------------- /SQL/183-Customers_Who_Never_Order.sql: -------------------------------------------------------------------------------- 1 | SELECT c.name AS Customers 2 | FROM Customers c 3 | LEFT JOIN Orders o 4 | ON c.id = o.customerId 5 | WHERE o.id IS NULL 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /React Machine Coding/Product_Cart_Publicis_Sapient/components/templates/CartLayout.js: -------------------------------------------------------------------------------- 1 | const CartLayout = ({ children }) => { 2 | return
{children}
; 3 | }; 4 | 5 | export default CartLayout; 6 | -------------------------------------------------------------------------------- /React Machine Coding/Stop Watch/Button.js: -------------------------------------------------------------------------------- 1 | export default function Button({ label, buttonHandler }) { 2 | return ( 3 | 6 | ); 7 | } 8 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Must Do DSA/Fibonacci.js: -------------------------------------------------------------------------------- 1 | function fibonacci(n) { 2 | const fib = [0, 1]; 3 | for( let i = 2; i < n; i++){ 4 | fib[i] = fib[i - 1] + fib[i - 2]; 5 | } 6 | return fib 7 | } 8 | 9 | console.log(fibonacci(5)) -------------------------------------------------------------------------------- /HackerRank/README.md: -------------------------------------------------------------------------------- 1 | Solutions to problems on [HackerRanK](https://www.hackerrank.com/) 2 | 3 |
4 | 5 |
6 | 7 | -------------------------------------------------------------------------------- /React Machine Coding/Redux Ecommerce Store/pages/ProductListing.jsx: -------------------------------------------------------------------------------- 1 | import Products from '../components/Products'; 2 | 3 | export default function ProductListing() { 4 | return ( 5 |
6 | 7 |
8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Must Do DSA/Factorial.js: -------------------------------------------------------------------------------- 1 | function factorial(n) { 2 | let result = 1; 3 | 4 | for( let i = 2; i <= n; i++){ 5 | result = result * i; 6 | } 7 | 8 | return result; 9 | } 10 | 11 | console.log(factorial(5)); -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0053_Max_SubArray.js: -------------------------------------------------------------------------------- 1 | var maxSubArray = function(nums) { 2 | mx = nums[0] 3 | sm = 0; 4 | nums.forEach((n) => { 5 | sm += n 6 | mx = Math.max(sm, mx); 7 | if(sm < 0) sm = 0; 8 | }) 9 | return mx; 10 | }; -------------------------------------------------------------------------------- /LeetCode/389-Find_The_Difference.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public char findTheDifference(String s, String t) { 3 | char c = 0; 4 | for(char cs : s.toCharArray()) c ^= cs; 5 | for(char ct : t.toCharArray()) c ^= ct; 6 | return c; 7 | } 8 | } -------------------------------------------------------------------------------- /React Machine Coding/Product_Cart_Publicis_Sapient/App.js: -------------------------------------------------------------------------------- 1 | import "./styles.css"; 2 | import CartPage from "./pages/CartPage"; 3 | 4 | export default function App() { 5 | return ( 6 |
7 | 8 |
9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /React Machine Coding/Product_Cart_Publicis_Sapient/components/atoms/Typography.js: -------------------------------------------------------------------------------- 1 | const Typography = ({ variant = "p", children }) => { 2 | const Tag = variant; 3 | return {children}; 4 | }; 5 | 6 | export default Typography; 7 | -------------------------------------------------------------------------------- /BigFrontEnd/BFE/JS/006_Implemement_Basic_Debounce.js: -------------------------------------------------------------------------------- 1 | function debounce(func, wait) { 2 | // your code here 3 | let timeoutId; 4 | 5 | return function(...args) { 6 | clearTimeout(timeoutId); 7 | timeoutId = setTimeout(() => func.call(this, ...args), wait); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /HackerRank/Problem Solving/108-A_very_big_sum.py: -------------------------------------------------------------------------------- 1 | def aVeryBigSum(ar,n): 2 | plus = 0 3 | for i in range(n): 4 | plus = plus + ar[i] 5 | print (plus) 6 | 7 | 8 | 9 | n = int(input()) 10 | 11 | ar = list(map(int, input().rstrip().split())) 12 | 13 | aVeryBigSum(ar,n) -------------------------------------------------------------------------------- /LeetCode/1304-Find_N_Unique_Integers_Sum_up_Zero.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] sumZero(int n) { 3 | int[] a = new int[n]; 4 | 5 | for(int i = 0; i < n; i++){ 6 | a[i]= 2*i - n + 1; 7 | } 8 | return a; 9 | } 10 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0070_Climbing_Stairs.js: -------------------------------------------------------------------------------- 1 | var climbStairs = function(n) { 2 | const dp = new Array(n + 1).fill(0); 3 | 4 | dp[0] = 1; 5 | dp[1] = 1; 6 | 7 | for (let i = 2; i <= n; i++) 8 | dp[i] = dp[i - 1] + dp[i - 2]; 9 | 10 | return dp[n]; 11 | }; -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Must Do DSA/LinearSearch.js: -------------------------------------------------------------------------------- 1 | function linearSearch(arr, target) { 2 | for (let i = 0; i < arr.length; i++) { 3 | if (arr[i] === target) { 4 | return i; 5 | } 6 | } 7 | return -1; 8 | } 9 | 10 | console.log(linearSearch([1, 2, 3, 4, 5], 3)); -------------------------------------------------------------------------------- /React Machine Coding/Redux Ecommerce Store/store/store.js: -------------------------------------------------------------------------------- 1 | import { configureStore } from '@reduxjs/toolkit'; 2 | import cartSlice from './cartSlice'; 3 | 4 | const store = configureStore({ 5 | reducer: { 6 | cart: cartSlice, 7 | }, 8 | }); 9 | 10 | export default store; 11 | -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/Closure.js: -------------------------------------------------------------------------------- 1 | function makeCounter() { 2 | let count = 0; 3 | 4 | return function () { 5 | return count++; 6 | }; 7 | } 8 | 9 | let counter = makeCounter(); 10 | console.log(counter()); 11 | console.log(counter()); 12 | console.log(counter()); -------------------------------------------------------------------------------- /React Machine Coding/Debounced Search/App.tsx: -------------------------------------------------------------------------------- 1 | import './App.css'; 2 | import DebounceSearch from './components/DebounceSearch/DebounceSearch'; 3 | 4 | function App() { 5 | return ( 6 | <> 7 | 8 | 9 | ); 10 | } 11 | 12 | export default App; 13 | -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/Callable_Function.js: -------------------------------------------------------------------------------- 1 | // callback function example 2 | 3 | function log(value) { 4 | console.log(value); 5 | } 6 | 7 | function findSum(num1, num2, print) { 8 | const sum = num1 + num2; 9 | 10 | print(sum); 11 | } 12 | 13 | findSum(20, 30, log); -------------------------------------------------------------------------------- /HackerRank/Problem Solving/111-Staircase.py: -------------------------------------------------------------------------------- 1 | import math 2 | import os 3 | import random 4 | import re 5 | import sys 6 | 7 | 8 | def staircase(n): 9 | for f in range(1,n+1): 10 | print(("#"*f).rjust(n)) 11 | 12 | if __name__ == '__main__': 13 | n = int(input()) 14 | 15 | staircase(n) -------------------------------------------------------------------------------- /LeetCode/007-Reverse_Integer.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverse(self, x: int) -> int: 3 | s = str(abs(x)) 4 | 5 | reversed = int(s[::-1]) 6 | 7 | if reversed > 2147483647: 8 | return 0 9 | 10 | return reversed if x > 0 else (reversed * -1) -------------------------------------------------------------------------------- /LeetCode/217-Contains_Duplicate.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean containsDuplicate(int[] nums) { 3 | Arrays.sort(nums); 4 | 5 | for(int i=0; i= fn.length){ 5 | return fn.apply(this, args) 6 | } else{ 7 | return curried.bind(this, ...args) 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Geeks For Geeks/DSA 450/006-Cyclically_Rotate_an_Array_by_One.java: -------------------------------------------------------------------------------- 1 | class Compute { 2 | 3 | public void rotate(int arr[], int n) 4 | { 5 | int temp=arr[n-1]; 6 | 7 | for(int i=n-1;i>0;i--){ 8 | arr[i]=arr[i-1]; 9 | } 10 | arr[0]=temp; 11 | } 12 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Must Do DSA/RecursiveFactorial.js: -------------------------------------------------------------------------------- 1 | function recursiveFactorial(n) { 2 | if (n === 0) { 3 | return 1; 4 | } 5 | return n * recursiveFactorial(n - 1); 6 | } 7 | 8 | console.log(recursiveFactorial(0)); 9 | console.log(recursiveFactorial(1)); 10 | console.log(recursiveFactorial(4)); -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0509_Fibonacci_Number.js: -------------------------------------------------------------------------------- 1 | var fib = function(n) { 2 | if (n <= 1) return n 3 | 4 | let prev1 = 0, prev2 = 1 5 | 6 | for(let i = 2; i<= n; i++){ 7 | let current = prev1 + prev2; 8 | prev1 = prev2 9 | prev2 = current 10 | } 11 | 12 | return prev2 13 | }; -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0100_Same_Tree.js: -------------------------------------------------------------------------------- 1 | var isSameTree = function(p, q) { 2 | if(p === null && q === null) return true 3 | if(p === null || q === null) return false 4 | 5 | if(p.val === q.val) { 6 | return isSameTree(p.left, q.left) && isSameTree(p.right, q.right) 7 | } 8 | 9 | return false 10 | }; -------------------------------------------------------------------------------- /React Machine Coding/HOC/Product Fetch/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import ProductWrapper from "./components/ProductListing"; 3 | import "./styles.css"; 4 | 5 | export default function App() { 6 | return ( 7 |
8 | 9 |
10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /BigFrontEnd/BFE/JS/0023_create_sum.js: -------------------------------------------------------------------------------- 1 | function sum(num, currentSum = 0) { 2 | // your code here 3 | const newCurrentSum = num + currentSum 4 | 5 | const func = (arg) => { 6 | return sum(arg, num + currentSum) 7 | } 8 | 9 | func.valueOf = () => newCurrentSum 10 | 11 | return func 12 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0141_Linked_List_Cycle.js: -------------------------------------------------------------------------------- 1 | 2 | var hasCycle = function(head) { 3 | let fast = head 4 | let slow = head 5 | 6 | while(fast && fast.next) { 7 | fast = fast.next.next 8 | slow = slow.next 9 | 10 | if (fast === slow) return true 11 | } 12 | 13 | return false 14 | }; -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0206_Reverse_Linked_List.js: -------------------------------------------------------------------------------- 1 | var reverseList = function(head) { 2 | let prev = null 3 | let curr = head; 4 | while(curr){ 5 | let next = curr.next; 6 | curr.next = prev; 7 | prev = curr 8 | curr = next; 9 | } 10 | head = prev 11 | 12 | return head 13 | }; -------------------------------------------------------------------------------- /React Machine Coding/Product_Cart_Publicis_Sapient/components/atoms/Button.js: -------------------------------------------------------------------------------- 1 | const Button = ({ children, onClick }) => ( 2 | 8 | ); 9 | 10 | export default Button; 11 | -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/Event_Delegration.js: -------------------------------------------------------------------------------- 1 | // Event Delegation Example 2 | 3 | const div = document.getElementById("div"); 4 | 5 | div.addEventListener("click", (event) => { 6 | const target = event.target; 7 | 8 | if (target.tagName === "BUTTON") { 9 | console.log(target.innerHTML); 10 | } 11 | }); -------------------------------------------------------------------------------- /CodeForces/B-Lovely_Palindromes.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main 4 | { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | StringBuilder number = new StringBuilder(sc.next()); 8 | System.out.println(number.toString()+""+number.reverse()); 9 | } 10 | } -------------------------------------------------------------------------------- /React Machine Coding/Star Rating/style.css: -------------------------------------------------------------------------------- 1 | .App { 2 | font-family: sans-serif; 3 | text-align: center; 4 | } 5 | 6 | .star-rating { 7 | font-size: 24px; 8 | } 9 | 10 | .star { 11 | cursor: pointer; 12 | } 13 | 14 | .star.hover { 15 | color: gold; 16 | } 17 | 18 | .star.active { 19 | color: orange; 20 | } 21 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Must Do DSA/RecursiveFibonacci.js: -------------------------------------------------------------------------------- 1 | function recursiveFibonacci(n) { 2 | if (n < 2) { 3 | return n; 4 | } 5 | return recursiveFibonacci(n - 1) + recursiveFibonacci(n - 2); 6 | } 7 | 8 | console.log(recursiveFibonacci(0)); 9 | console.log(recursiveFibonacci(1)); 10 | console.log(recursiveFibonacci(4)); -------------------------------------------------------------------------------- /React Machine Coding/OTP Login/styles.css: -------------------------------------------------------------------------------- 1 | /* ----------------------Mobile Login------------------------ */ 2 | .mobile__login { 3 | text-align: center; 4 | margin: auto; 5 | } 6 | 7 | .otpInput { 8 | width: 40px; 9 | height: 40px; 10 | margin: 5px; 11 | text-align: center; 12 | font-size: 1.2em; 13 | } -------------------------------------------------------------------------------- /HackerRank/Problem Solving/102-Drawing_Book.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | int n, p, w1, w2; 9 | 10 | cin>>n; 11 | cin>>p; 12 | 13 | w1 = p/2; 14 | w2 = n/2 - p/2; 15 | 16 | if(w1 < w2) 17 | cout< List[int]: 3 | n = len(nums) 4 | arr = [] 5 | for i in range (0,n-1): 6 | for j in range (i+1,n): 7 | if(nums[i]+nums[j]==target): 8 | arr.append(i) 9 | arr.append(j) 10 | return arr -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Must Do DSA/Prime_Number_Check.js: -------------------------------------------------------------------------------- 1 | function isPrime(n){ 2 | if(n < 2) { 3 | return false; 4 | } 5 | 6 | for( let i = 2; i < Math.sqrt(n); i++){ 7 | if(n % i === 0) { 8 | return false; 9 | } 10 | } 11 | 12 | return true; 13 | } 14 | 15 | console.log(isPrime(5)) 16 | console.log(isPrime(35)) -------------------------------------------------------------------------------- /Daily Bytes/008-Jewels_and_Stones.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numJewelsInStones(String jewels, String stones) { 3 | int num_j = 0; 4 | 5 | for(int i = 0; i < stones.length(); i++){ 6 | if(jewels.indexOf(stones.charAt(i)) > -1){ 7 | num_j += 1; 8 | } 9 | } 10 | return num_j; 11 | } 12 | } -------------------------------------------------------------------------------- /LeetCode/771-Jewels_and_Stones.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numJewelsInStones(String jewels, String stones) { 3 | int num_j = 0; 4 | 5 | for(int i = 0; i < stones.length(); i++){ 6 | if(jewels.indexOf(stones.charAt(i)) > -1){ 7 | num_j += 1; 8 | } 9 | } 10 | return num_j; 11 | } 12 | } -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0122_Best_Time_Buy_Sell_Stock_II.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxProfit(int[] prices) { 3 | int profit = 0; 4 | for(int i = 1; i < prices.length; i++){ 5 | if(prices[i] > prices[i-1]){ 6 | profit += prices[i] - prices[i-1]; 7 | } 8 | } 9 | return profit; 10 | } 11 | } -------------------------------------------------------------------------------- /LeetCode/053-Maximum_Subarray.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxSubArray(int[] nums) { 3 | int sum = 0; 4 | int max = nums[0]; 5 | for(int i = 0; i < nums.length; i++){ 6 | sum += nums[i]; 7 | 8 | if(sum > max) max = sum; 9 | if(sum < 0) sum = 0; 10 | } 11 | return max; 12 | } 13 | } -------------------------------------------------------------------------------- /HackerRank/Problem Solving/112-Mini_Max_Sum.py: -------------------------------------------------------------------------------- 1 | import math 2 | import os 3 | import random 4 | import re 5 | import sys 6 | 7 | 8 | def miniMaxSum(arr): 9 | arr.sort() 10 | mins=sum(arr[0:4]) 11 | maxs=sum(arr[1:5]) 12 | print(mins, maxs) 13 | 14 | 15 | 16 | 17 | if __name__ == '__main__': 18 | arr = list(map(int, input().rstrip().split())) 19 | 20 | miniMaxSum(arr) -------------------------------------------------------------------------------- /BigFrontEnd/BFE/JS/0003_implement_Array.prototype.flat.js: -------------------------------------------------------------------------------- 1 | function flat(arr, depth = 1) { 2 | // your imeplementation here 3 | let result = [] 4 | 5 | for(let item of arr){ 6 | if (Array.isArray(item) && depth > 0){ 7 | result.push(...flat(item, depth - 1)); 8 | } else { 9 | result.push(item) 10 | } 11 | } 12 | 13 | return result 14 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /1796_Second_Largest_Digit_String.js: -------------------------------------------------------------------------------- 1 | var secondHighest = function(s) { 2 | let digits = new Set() 3 | 4 | for(let char of s) { 5 | if(!isNaN(char)){ 6 | digits.add(Number(char)) 7 | } 8 | } 9 | 10 | let sorteddigits = Array.from(digits).sort((a, b) => b - a) 11 | 12 | return sorteddigits.length >= 2 ? sorteddigits[1] : -1 13 | }; -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0098_Validate_Binary_Search_Tree.js: -------------------------------------------------------------------------------- 1 | var isValidBST = function(root) { 2 | function recurse(root, min, max) { 3 | if(root === null) return true 4 | 5 | if(root.val >= max || root.val <= min) return false 6 | 7 | return recurse(root.left, min, root.val) && recurse(root.right, root.val, max) 8 | } 9 | 10 | return recurse(root, -Infinity, Infinity) 11 | }; -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/Map_Polyfill.js: -------------------------------------------------------------------------------- 1 | // Polyfill for map 2 | Array.prototype.myMap = function (cb) { 3 | let temp = []; 4 | for (let i = 0; i < this.length; i++) { 5 | temp.push(cb(this[i], i, this)); 6 | } 7 | 8 | return temp; 9 | }; 10 | 11 | const multiplyThree = nums.myMap((num, index, arr) => { 12 | return num * 3; 13 | }); 14 | 15 | console.log(multiplyThree); -------------------------------------------------------------------------------- /DSA SHEET Solution/215-Kth_Max_Element.java: -------------------------------------------------------------------------------- 1 | // Problem URL - https://leetcode.com/problems/kth-largest-element-in-an-array/description/ 2 | // Problem Solution - https://www.youtube.com/watch?v=9s6ZcFZ_3ys&list=PLzffTJx5aHaRMfFodb4O5yyi6uSA4Q3E0&index=3 3 | 4 | class Solution { 5 | public int findKthLargest(int[] nums, int k) { 6 | Arrays.sort(nums); 7 | return nums[nums.length-k]; 8 | } 9 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Must Do DSA/BubbleSort.js: -------------------------------------------------------------------------------- 1 | function BubbleSort(nums) { 2 | for (let i = 0; i < nums.length - 1; i++) { 3 | for (let j = 0; j < nums.length - i; j++) { 4 | if (nums[j] > nums[j + 1]) { 5 | [nums[j], nums[j + 1]] = [nums[j + 1], nums[j]]; 6 | } 7 | } 8 | } 9 | 10 | return nums; 11 | } 12 | 13 | let nums = [5, 6, 2, 3, 8, 8, 10, 9]; 14 | console.log(BubbleSort(nums)); 15 | -------------------------------------------------------------------------------- /LeetCode/206-Reverse_Linked_List.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public ListNode reverseList(ListNode head) { 3 | 4 | ListNode prev = null; 5 | 6 | while(head != null){ 7 | ListNode next = head.next; 8 | head.next = prev; 9 | prev = head; 10 | head = next; 11 | } 12 | 13 | return prev; 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/Filter_Polyfill.js: -------------------------------------------------------------------------------- 1 | // Polyfill for filter 2 | Array.prototype.myFilter = function (cb) { 3 | let temp = []; 4 | for (let i = 0; i < this.length; i++) { 5 | if (cb(this[i], i, this)) temp.push(this[i]); 6 | } 7 | 8 | return temp; 9 | }; 10 | 11 | const moreThanTwo = nums.myFilter((num) => { 12 | return num > 2; 13 | }); 14 | 15 | console.log(moreThanTwo); -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/Reduce_Polyfill.js: -------------------------------------------------------------------------------- 1 | Array.prototype.myReduce = function (cb, initialValue) { 2 | let acc = initialValue; 3 | 4 | for (let i = 0; i < this.length; i++) { 5 | acc = acc ? cb(acc, this[i], i, this) : this[i]; 6 | } 7 | 8 | return acc; 9 | }; 10 | 11 | const sum = nums.myReduce((acc, curr, i, arr) => { 12 | return acc + curr; 13 | }, 0); 14 | 15 | console.log(sum); -------------------------------------------------------------------------------- /React Machine Coding/File Manager/App.jsx: -------------------------------------------------------------------------------- 1 | import "./styles.css"; 2 | import { useState } from "react"; 3 | import explorer from "./data/folderInfo.json"; 4 | import Folder from "./components/Folder"; 5 | 6 | export default function App() { 7 | const [explorerData, setExplorerData] = useState(explorer); 8 | return ( 9 |
10 | 11 |
12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/useToggle/useToggle.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | export default function useToggle(defaultValue = false) { 4 | const [value, setValue] = useState(defaultValue); 5 | 6 | function toggleValue(value) { 7 | setValue((currentValue) => { 8 | typeof value === "boolean" ? value : !currentValue; 9 | }); 10 | } 11 | 12 | return [value, toggleValue]; 13 | } 14 | -------------------------------------------------------------------------------- /React Machine Coding/Product_Cart_Publicis_Sapient/pages/CartPage.js: -------------------------------------------------------------------------------- 1 | import CartLayout from "../components/templates/CartLayout"; 2 | import CartList from "../components/organisms/CartList"; 3 | 4 | const CartPage = () => { 5 | return ( 6 | 7 |

Your Cart

8 | 9 |
10 | ); 11 | }; 12 | 13 | export default CartPage; 14 | -------------------------------------------------------------------------------- /HackerRank/Problem Solving/107-Compare_the_Triplets.py: -------------------------------------------------------------------------------- 1 | def compareTriplets(a, b): 2 | n = len(a) 3 | alice=0 4 | bob = 0 5 | for i in range (n): 6 | if (a[i]>b[i]): 7 | alice+=1 8 | elif(a[i] 9 | 10 | 11 | 12 | 13 | ); 14 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0049_Group_Anagram.js: -------------------------------------------------------------------------------- 1 | var groupAnagrams = function(strs) { 2 | let sorted = strs.map((str) => str.split("").sort().join("")) 3 | let map = {}; 4 | 5 | for(let i = 0; i < sorted.length; i++){ 6 | if(!map[sorted[i]]) { 7 | map[sorted[i]] = [strs[i]] 8 | } else { 9 | map[sorted[i]].push(strs[i]) 10 | } 11 | } 12 | 13 | return Object.values(map) 14 | }; -------------------------------------------------------------------------------- /LeetCode/014-Longest_Common_Prefix.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestCommonPrefix(self, strs: List[str]) -> str: 3 | 4 | if not strs: 5 | return "" 6 | 7 | strs.sort() 8 | first = strs[0] 9 | last = strs[-1] 10 | 11 | i=0 12 | 13 | while i { 2 | const response = await fetch("https://fakestoreapi.com/carts/1"); 3 | return response.json(); 4 | }; 5 | 6 | export const fetchProduct = async (productId) => { 7 | const response = await fetch( 8 | `https://fakestoreapi.com/products/${productId}` 9 | ); 10 | return response.json(); 11 | }; 12 | -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0058_Length_Of_Last_Word.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int lengthOfLastWord(String s) { 3 | int length = 0; 4 | int i = s.length() - 1; 5 | 6 | while(i >= 0 && s.charAt(i)==' '){ 7 | i--; 8 | } 9 | 10 | while(i >= 0 && s.charAt(i) != ' '){ 11 | length++; 12 | i--; 13 | } 14 | 15 | return length; 16 | } 17 | } -------------------------------------------------------------------------------- /Geeks For Geeks/DSA 450/005-Union_Of_Two_Arrays.java: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public static int doUnion(int a[], int n, int b[], int m) 3 | { 4 | //Your code here 5 | HashSet set = new HashSet<>(); 6 | for(int i = 0; i < n; i++){ 7 | set.add(a[i]); 8 | } 9 | for(int j = 0; j < m; j++){ 10 | set.add(b[j]); 11 | } 12 | return set.size(); 13 | } 14 | } -------------------------------------------------------------------------------- /CodeForces/A-Digits_Sum.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class DigitalSum{ 4 | 5 | public static void main(String []args){ 6 | Scanner sc = new Scanner(System.in); 7 | int t = sc.nextInt(); 8 | while(t-- >= 1){ 9 | int n = sc.nextInt(); 10 | int ans; 11 | 12 | ans = (n+1) / 10; 13 | 14 | System.out.println(ans); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /HackerRank/Problem Solving/106-Simple_Array_Sum.py: -------------------------------------------------------------------------------- 1 | def simpleArraySum(ar,n): 2 | sum = 0 3 | for i in range(n): 4 | sum = sum +ar[i] 5 | return sum 6 | 7 | if __name__ == '__main__': 8 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 9 | 10 | n = int(input()) 11 | 12 | ar = list(map(int, input().rstrip().split())) 13 | 14 | result = simpleArraySum(ar,n) 15 | 16 | fptr.write(str(result) + '\n') 17 | 18 | fptr.close() -------------------------------------------------------------------------------- /LeetCode/038-Count_And_Say.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countAndSay(self, n: int) -> str: 3 | sequence = [1] 4 | for _ in range(n-1): 5 | next = [] 6 | for num in sequence: 7 | if not next or next[-1] != num: 8 | next+= [1,num] 9 | else: 10 | next[-2]+=1 11 | sequence = next 12 | 13 | return "".join(map(str,sequence)) -------------------------------------------------------------------------------- /HackerRank/Problem Solving/104-Designer_PDF_Viewer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int H[26]; 8 | for(int i = 0; i < 26; ++i) 9 | cin >> H[i]; 10 | 11 | string word; 12 | cin >> word; 13 | 14 | int big_h = 0; 15 | for(char i : word) 16 | if(H[(int)i-97] > big_h) big_h = H[(int)i-97]; 17 | 18 | cout << big_h * word.size() << endl; 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /LeetCode/344-Reverse_String.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void reverseString(char[] s) { 3 | int a_pointer = 0; 4 | int b_pointer = s.length - 1; 5 | 6 | while(a_pointer <= b_pointer){ 7 | char temp = s[a_pointer]; 8 | s[a_pointer] = s[b_pointer]; 9 | s[b_pointer] = temp; 10 | 11 | a_pointer += 1; 12 | b_pointer -= 1; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0026_Remove_Duplicates_Sorted_Array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removeDuplicates(int[] nums) { 3 | if(nums == null || nums.length == 0) return 0; 4 | 5 | int k = 1; 6 | 7 | for(int i = 1; i < nums.length; i++){ 8 | if(nums[i] != nums[k-1]){ 9 | nums[k] = nums[i]; 10 | k++; 11 | } 12 | } 13 | 14 | return k; 15 | } 16 | } -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0080_Remove_Duplicates_Sorted_Array_II.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removeDuplicates(int[] nums) { 3 | if(nums.length <= 2) return nums.length; 4 | 5 | int k = 2; 6 | 7 | for(int i = 2; i < nums.length; i++){ 8 | if(nums[i] != nums[k-2]){ 9 | nums[k] = nums[i]; 10 | k++; 11 | } 12 | } 13 | 14 | return k; 15 | } 16 | } -------------------------------------------------------------------------------- /LeetCode/617-Merge_Two_Binary_Trees.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public TreeNode mergeTrees(TreeNode t1, TreeNode t2) { 3 | if(t1 == null){ 4 | return t2; 5 | } 6 | 7 | if(t2 == null){ 8 | return t1; 9 | } 10 | 11 | t1.val += t2.val; 12 | t1.left = mergeTrees(t1.left, t2.left); 13 | t1.right = mergeTrees(t1.right, t2.right); 14 | return t1; 15 | } 16 | } -------------------------------------------------------------------------------- /LeetCode/README.md: -------------------------------------------------------------------------------- 1 |

LeetCode Problems and Challenges Solutions

2 | 3 | Remember solutions are only solutions to given problems. If you want full study checklist for code & whiteboard interview, please turn to [jwasham's coding-interview-university](https://github.com/jwasham/coding-interview-university). 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Interview Exp/MoveZeroes.js: -------------------------------------------------------------------------------- 1 | function moveZeroes(nums) { 2 | let insertPos = 0; 3 | 4 | for (let i = 0; i < nums.length; i++) { 5 | if (nums[i] !== 0) { 6 | nums[insertPos] = nums[i]; 7 | insertPos += 1; 8 | } 9 | } 10 | 11 | while (insertPos < nums.length) { 12 | nums[insertPos] = 0; 13 | insertPos += 1; 14 | } 15 | 16 | return nums; 17 | } 18 | 19 | let nums = [0, 1, 2, 3, 0, 1, 2, 3, 5]; 20 | console.log(moveZeroes(nums)); -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Interview Exp/NonRepeatingChar.js: -------------------------------------------------------------------------------- 1 | function firstNonRepeatingChar(str) { 2 | const charCounts = new Map(); 3 | 4 | for (const char of str) { 5 | charCounts.set(char, (charCounts.get(char) || 0) + 1); 6 | } 7 | 8 | for (const char of str) { 9 | if (charCounts.get(char) === 1) { 10 | return char; 11 | } 12 | } 13 | 14 | return null; 15 | } 16 | 17 | console.log(firstNonRepeatingChar("swiss")); // Output: "w" 18 | 19 | -------------------------------------------------------------------------------- /Daily Bytes/009-Detect_Capital.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean detectCapitalUse(String word) { 3 | int count = 0; 4 | 5 | for(int i = 0; i < word.length(); i++){ 6 | if(Character.isUpperCase(word.charAt(i))){ 7 | count++; 8 | } 9 | } 10 | 11 | return count == word.length() || count == 0 || count == 1 && Character.isUpperCase(word.charAt(0)); 12 | 13 | } 14 | } -------------------------------------------------------------------------------- /LeetCode/520-Detect_Capital.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean detectCapitalUse(String word) { 3 | int count = 0; 4 | 5 | for(int i = 0; i < word.length(); i++){ 6 | if(Character.isUpperCase(word.charAt(i))){ 7 | count++; 8 | } 9 | } 10 | 11 | return count == word.length() || count == 0 || count == 1 && Character.isUpperCase(word.charAt(0)); 12 | 13 | } 14 | } -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0392_Is_Subsequence.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isSubsequence(String s, String t) { 3 | int sIndex = 0; 4 | int tIndex = 0; 5 | 6 | while(sIndex < s.length() && tIndex < t.length()){ 7 | if(s.charAt(sIndex) == t.charAt(tIndex)){ 8 | sIndex++; 9 | } 10 | 11 | tIndex++; 12 | } 13 | 14 | return sIndex == s.length(); 15 | } 16 | } -------------------------------------------------------------------------------- /React Machine Coding/JS Machine Coding/Tabs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Sandbox 5 | 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0235_Lowest_Common_Ancestor_Binary_Search_Tree.js: -------------------------------------------------------------------------------- 1 | var lowestCommonAncestor = function(root, p, q) { 2 | let small = Math.min(p.val, q.val) 3 | let large = Math.max(p.val, q.val) 4 | 5 | while(root){ 6 | if (root.val > large){ 7 | root = root.left 8 | } else if (root.val < small) { 9 | root = root.right 10 | } else { 11 | return root 12 | } 13 | } 14 | return null 15 | }; -------------------------------------------------------------------------------- /LeetCode/557-Reverse_Words_in_a_String_III.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String reverseWords(String s) { 3 | String[] arr = s.split(" "); 4 | for(int i = 0; i < arr.length; i++) 5 | arr[i] = new StringBuilder(arr[i]).reverse().toString(); 6 | 7 | StringBuilder res = new StringBuilder(s.length()); 8 | 9 | for(String w : arr) res.append(w + " "); 10 | 11 | return res.toString().trim(); 12 | } 13 | } -------------------------------------------------------------------------------- /React Machine Coding/HOC/Product Fetch/ProductListing.js: -------------------------------------------------------------------------------- 1 | import withProductFetch from "./withProductFetch"; 2 | 3 | function ProductListing({ products }) { 4 | return ( 5 |
6 | {products.map((prod) => ( 7 |
8 |

{prod.name}

9 |

{prod.desc}

10 |
11 | ))} 12 |
13 | ); 14 | } 15 | 16 | const ProductWrapper = withProductFetch(ProductListing); 17 | 18 | export default ProductWrapper; 19 | -------------------------------------------------------------------------------- /React Machine Coding/Pop Up/Pop.js: -------------------------------------------------------------------------------- 1 | export default function Pop(props) { 2 | return props.trigger ? ( 3 |
4 |
5 | 11 | {props.children} 12 |
13 |
14 | ) : ( 15 | "" 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /HackerRank/Problem Solving/113-Birthday_Cake_Candles.py: -------------------------------------------------------------------------------- 1 | import math 2 | import os 3 | import random 4 | import re 5 | import sys 6 | 7 | # Complete the birthdayCakeCandles function below. 8 | def birthdayCakeCandles(ar,n): 9 | m = max(ar) 10 | count = 0 11 | for i in range(n): 12 | if(ar[i]==m): 13 | count+=1 14 | print (count) 15 | 16 | 17 | 18 | n = int(input()) 19 | 20 | ar = list(map(int, input().rstrip().split())) 21 | 22 | birthdayCakeCandles(ar,n) 23 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Must Do DSA/SelectionSort.js: -------------------------------------------------------------------------------- 1 | let nums = [5, 7, 2, 3, 4, 20, 19, 11]; 2 | 3 | function selectionSort(arr) { 4 | for (let i = 0; i < arr.length - 1; i++) { 5 | let minIndex = i; 6 | for (let j = i + 1; j < arr.length; j++) { 7 | if (nums[j] < nums[minIndex]) { 8 | minIndex = j; 9 | } 10 | } 11 | 12 | [nums[i], nums[minIndex]] = [nums[minIndex], nums[i]]; 13 | } 14 | 15 | return arr; 16 | } 17 | 18 | console.log(selectionSort(nums)); 19 | -------------------------------------------------------------------------------- /LeetCode/066-Plus_One.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] plusOne(int[] digits) { 3 | int n = digits.length; 4 | 5 | for(int i = n -1; i >= 0; i--){ 6 | if(digits[i] < 9){ 7 | digits[i]++; 8 | return digits; 9 | } 10 | 11 | digits[i] = 0; 12 | } 13 | 14 | int[] new_number = new int[n+1]; 15 | new_number[0] = 1; 16 | return new_number; 17 | } 18 | } -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/useToggle/TogglePage.js: -------------------------------------------------------------------------------- 1 | import useToggle from "./useToggle"; 2 | 3 | export default function TogglePage() { 4 | const [value, toggleValue] = useToggle(false); 5 | 6 | return ( 7 |
8 |
{value.toString()}
9 | 10 | 11 | 12 |
13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /CodeForces/A-String_Task.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | string s,s2; 7 | cin>>s; 8 | int len=s.length(); 9 | 10 | for(int i=0;i= 0; i--){ 8 | reversed.append(words[i]); 9 | 10 | if(i > 0){ 11 | reversed.append(" "); 12 | } 13 | } 14 | 15 | return reversed.toString(); 16 | } 17 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0152_Maximum_Product_Subarray.js: -------------------------------------------------------------------------------- 1 | var maxProduct = function(nums) { 2 | let n = nums.length 3 | let leftprod = 1 4 | let rightprod = 1 5 | let ans = nums[0] 6 | 7 | for(let i = 0; i < n; i++){ 8 | leftprod = leftprod == 0 ? 1 : leftprod; 9 | rightprod = rightprod == 0 ? 1 : rightprod; 10 | 11 | leftprod *= nums[i] 12 | rightprod *= nums[n-1-i] 13 | 14 | ans = Math.max(ans, Math.max(rightprod, leftprod)) 15 | } 16 | return ans 17 | }; -------------------------------------------------------------------------------- /React Machine Coding/JS Machine Coding/Tabs/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: sans-serif; 3 | } 4 | 5 | .tabContent { 6 | display: none; 7 | } 8 | 9 | .tabLinks { 10 | background-color: #f2f2f2; 11 | padding: 10px 20px; 12 | border: 1px solid #ccc; 13 | cursor: pointer; 14 | } 15 | 16 | .tabLinks:hover { 17 | background-color: #ddd; 18 | } 19 | 20 | .tabLinks.active { 21 | background-color: #ddd; 22 | color: #333; 23 | } 24 | 25 | .tabContent.active { 26 | display: block; 27 | } 28 | -------------------------------------------------------------------------------- /React Machine Coding/JS Machine Coding/Search Typehead/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Sandbox 5 | 6 | 7 | 8 | 9 | 10 |

Search with Debounce

11 | 12 |
    13 |
    14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0704_Binary_Search.js: -------------------------------------------------------------------------------- 1 | var search = function(nums, target) { 2 | let start = 0; 3 | let end = nums.length - 1; 4 | 5 | while (start <= end) { 6 | let middle = Math.floor((start + end) / 2 ); 7 | let foundVal = nums[middle] 8 | 9 | if(foundVal === target) { 10 | return middle 11 | } else if (foundVal < target){ 12 | start = middle + 1 13 | } else { 14 | end = middle - 1 15 | } 16 | } 17 | 18 | return -1; 19 | }; -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0121_Best_Time_Buy_Sell_Stock.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxProfit(int[] prices) { 3 | int minprice = Integer.MAX_VALUE; 4 | int maxprofit = 0; 5 | 6 | for(int i = 0; i < prices.length; i++){ 7 | if(prices[i] < minprice){ 8 | minprice = prices[i]; 9 | }else if(prices[i] - minprice > maxprofit){ 10 | maxprofit = prices[i] - minprice; 11 | } 12 | } 13 | return maxprofit; 14 | } 15 | } -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/customHook.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | export default function useToggle(initialState = false) { 4 | [state, setState] = useState(initialState); 5 | 6 | const handleTrue = () => setState(true); 7 | const handleFalse = () => setState(false); 8 | const handleToggle = () => setState(!state); 9 | 10 | return [ 11 | state, 12 | { 13 | setTrue: handleTrue, 14 | setFalse: handleFalse, 15 | setToggle: handleToggle, 16 | }, 17 | ]; 18 | } 19 | -------------------------------------------------------------------------------- /React Machine Coding/Progress Bar/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import ProgressBar from "./components/ProgressBar/ProgressBar"; 3 | 4 | import "./styles.css"; 5 | 6 | export default function App() { 7 | const [value, setValue] = useState(0); 8 | 9 | useEffect(() => { 10 | setInterval(() => { 11 | setValue((val) => val + 1); 12 | }, 100); 13 | }, []); 14 | 15 | return ( 16 |
    17 | 18 |
    19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /Geeks For Geeks/DSA 450/002-Finding_Kth_Min_Element.java: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public static int kthSmallest(int[] arr, int l, int r, int k) 3 | { 4 | //Your code here 5 | int n = l - r + 1; 6 | 7 | Queue pq = new PriorityQueue<>(Collections.reverseOrder()); 8 | for(int i = 0; i < arr.length; i++){ 9 | pq.add(arr[i]); 10 | if(pq.size() > k){ 11 | pq.remove(); 12 | } 13 | } 14 | return pq.peek(); 15 | } 16 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0020_Valid_Parentheses.js: -------------------------------------------------------------------------------- 1 | var isValid = function(s) { 2 | let stack = [] 3 | let i = 0; 4 | const paren = '{} () []' 5 | 6 | while( i < s.length){ 7 | stack.push(s[i]) 8 | i++; 9 | 10 | let open = stack[stack.length-2] 11 | let closed = stack[stack.length-1] 12 | let validparen = open + closed 13 | 14 | if(paren.includes(validparen)){ 15 | stack.pop() 16 | stack.pop() 17 | } 18 | } 19 | return stack.length === 0; 20 | }; -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/PromiseRace.js: -------------------------------------------------------------------------------- 1 | function promiseRace(promiseTask) { 2 | return new Promise((resolve, reject) => { 3 | for (let i = 0; i < promiseTask.length; i++) { 4 | Promise.resolve(promiseTask[i]).then(resolve).catch(reject); 5 | } 6 | }); 7 | } 8 | 9 | const promise1 = new Promise((resolve) => 10 | setTimeout(() => resolve("Quick"), 300) 11 | ); 12 | const promise2 = new Promise((resolve) => 13 | setTimeout(() => resolve("Slow"), 1000) 14 | ); 15 | 16 | promiseRace([promise1, promise2]).then(console.log); 17 | -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0001_Two_Sum.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] twoSum(int[] nums, int target) { 3 | Map numMap = new HashMap<>(); 4 | for (int i = 0; i < nums.length; i++) { 5 | int complement = target - nums[i]; 6 | if (numMap.containsKey(complement)) { 7 | return new int[] { numMap.get(complement), i }; 8 | } else { 9 | numMap.put(nums[i], i); 10 | } 11 | } 12 | return new int[] {}; 13 | } 14 | } -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/Currying.js: -------------------------------------------------------------------------------- 1 | function sum(...args) { 2 | let total = args.reduce((a, b) => a + b, 0); 3 | 4 | function innerSum(...nextArgs) { 5 | total += nextArgs.reduce((a, b) => a + b, 0); 6 | return innerSum; 7 | } 8 | 9 | innerSum.valueOf = function () { 10 | return total; 11 | }; 12 | 13 | innerSum.toString = function () { 14 | return total; 15 | }; 16 | 17 | return innerSum; 18 | } 19 | 20 | let s = sum(1)(2)(5)(8); 21 | console.log(s.toString()); 22 | //console.log(s.toValue()); -------------------------------------------------------------------------------- /LeetCode/050-Pow_x_ n.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public double myPow(double x, int n) { 3 | double ans = 1.0; 4 | long nn = n; 5 | if(nn < 0) nn = -1 * nn; 6 | while(nn > 0){ 7 | if(nn % 2 == 1){ 8 | ans = ans * x; 9 | nn = nn - 1; 10 | } 11 | else{ 12 | x = x * x; 13 | nn = nn / 2; 14 | } 15 | } 16 | if( n < 0) ans = (double)(1.0) / (double)(ans); 17 | return ans; 18 | } 19 | } -------------------------------------------------------------------------------- /React Machine Coding/useContext/ThemeContext.js: -------------------------------------------------------------------------------- 1 | import React, { createContext, useState } from "react"; 2 | 3 | export const ThemeContext = createContext(); 4 | 5 | export const ThemeProvider = ({ children }) => { 6 | const [theme, setTheme] = useState("light"); 7 | 8 | const toggleTheme = () => { 9 | setTheme((prevTheme) => (prevTheme === "light" ? "dark" : "light")); 10 | }; 11 | 12 | return ( 13 | 14 | {children} 15 | 16 | ); 17 | }; 18 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0011_Container_with_Most_Water.js: -------------------------------------------------------------------------------- 1 | var maxArea = function(height) { 2 | let left = 0 3 | let right = height.length - 1 4 | let maxima = 0 5 | 6 | while(left < right){ 7 | let width = right - left 8 | let maxArea = Math.min(height[left], height[right]) * width 9 | 10 | maxima = Math.max(maxima, maxArea) 11 | 12 | if(height[left] <= height[right]){ 13 | left+=1 14 | } else { 15 | right-=1; 16 | } 17 | } 18 | 19 | return maxima; 20 | }; 21 | -------------------------------------------------------------------------------- /LeetCode/242-Valid_Anagram.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isAnagram(String s, String t) { 3 | if(s.length() != t.length()) 4 | return false; 5 | 6 | int[] char_count = new int[26]; 7 | for(int i = 0 ; i < s.length(); i++){ 8 | char_count[s.charAt(i) - 'a']++; 9 | char_count[t.charAt(i) - 'a']--; 10 | } 11 | 12 | for(int count : char_count){ 13 | if(count != 0) 14 | return false; 15 | } 16 | return true; 17 | } 18 | } -------------------------------------------------------------------------------- /LeetCode/876-Middle_Of_the_Linked_List.java: -------------------------------------------------------------------------------- 1 | // This question is asked by Amazon. Given a non-empty linked list, return the middle node of the list. If the linked list contains an even number of elements, return the node closer to the end. 2 | 3 | class Solution { 4 | public ListNode middleNode(ListNode head) { 5 | ListNode slow = head, fast = head; 6 | 7 | while(fast != null && fast.next != null){ 8 | slow = slow.next; 9 | fast = fast.next.next; 10 | } 11 | 12 | return slow; 13 | } 14 | } -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/Event_Bubbling.js: -------------------------------------------------------------------------------- 1 | //Event Bubbling Example 2 | 3 | const div = document.getElementById("div"); 4 | const span = document.getElementById("span"); 5 | const button = document.getElementById("button"); 6 | 7 | div.addEventListener("click", () => { 8 | console.log("div was clicked"); 9 | }); 10 | span.addEventListener("click", () => { 11 | console.log("span was clicked"); 12 | }); 13 | button.addEventListener("click", (event) => { 14 | // event.stopPropagation(); 15 | console.log("button was clicked"); 16 | }); -------------------------------------------------------------------------------- /Dot Net Repository /DSA C#/ReverseString.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class StringReverser 4 | { 5 | public static void Main(string[] args) 6 | { 7 | string originalString = "C# is fun"; 8 | string reversedString = ""; 9 | 10 | for (int i = originalString.Length - 1; i >= 0; i--) 11 | { 12 | reversedString += originalString[i]; 13 | } 14 | 15 | Console.WriteLine($"Original string: {originalString}"); 16 | Console.WriteLine($"Reversed string: {reversedString}"); 17 | } 18 | } -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/useDebounce/useDebounce.js: -------------------------------------------------------------------------------- 1 | const { useState, useEffect } = require("react"); 2 | 3 | const useDebounce = (value, delay, cb = () => {}) => { 4 | const [debouncedValue, setDebouncedValue] = useState(value); 5 | 6 | useEffect(() => { 7 | let timer = setTimeout(() => { 8 | setDebouncedValue(value); 9 | cb(); 10 | }, delay); 11 | 12 | return () => { 13 | clearTimeout(timer); 14 | }; 15 | }, [value, delay]); 16 | 17 | return debouncedValue; 18 | }; 19 | 20 | export default useDebounce; -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0383_Ransom_Note.js: -------------------------------------------------------------------------------- 1 | var canConstruct = function(ransomNote, magazine) { 2 | if(ransomNote.length > magazine.length){ 3 | return false 4 | } 5 | 6 | const magazineTable = {} 7 | for(let c of magazine){ 8 | magazineTable[c] = (magazineTable[c] || 0 ) + 1 9 | } 10 | 11 | for (let c of ransomNote) { 12 | const tableChar = magazineTable[c] || 0 13 | if(tableChar === 0) 14 | return false 15 | magazineTable[c] = magazineTable[c] - 1 16 | } 17 | 18 | return true; 19 | }; -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0733_Flood_Fill.js: -------------------------------------------------------------------------------- 1 | var floodFill = function(image, sr, sc, color) { 2 | let prevColor = image[sr][sc] 3 | if(prevColor == color) return image; 4 | image[sr][sc] = color 5 | 6 | let dir = [[0,-1], [0, 1], [1, 0], [-1, 0]] 7 | 8 | for(let d of dir){ 9 | let r = sr + d[0] 10 | let c = sc + d[1] 11 | 12 | if (r < 0 || r >= image.length || c < 0 || c >= image[0].length) continue; 13 | if (image[r][c] == prevColor) floodFill(image, r, c, color); 14 | 15 | } 16 | 17 | return image; 18 | }; -------------------------------------------------------------------------------- /React Machine Coding/JS Machine Coding/Counter/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Sandbox 5 | 6 | 7 | 8 | 9 | 10 |

    Counter App

    11 |
    12 | 13 |
    0
    14 | 15 |
    16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /LeetCode/189-Rotate_Array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void rotate(int[] nums, int k) { 3 | k = k % nums.length; 4 | reverse(nums, 0 , nums.length - 1); 5 | reverse(nums, 0 , k - 1); 6 | reverse(nums, k , nums.length - 1); 7 | } 8 | 9 | public void reverse(int[] nums, int start, int end){ 10 | while(start < end){ 11 | int temp = nums[start]; 12 | nums[start] = nums[end]; 13 | nums[end] = temp; 14 | start++; 15 | end--; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0169_Majority_Element.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int majorityElement(int[] nums) { 3 | Integer candidate = null; 4 | int count = 0; 5 | 6 | for(int num : nums){ 7 | if(count == 0){ 8 | candidate = num; 9 | } 10 | 11 | if(num == candidate){ 12 | count++; 13 | } else{ 14 | count--; 15 | } 16 | } 17 | 18 | return candidate; 19 | } 20 | } 21 | 22 | // Boyer-Moore Voting Algorithm -------------------------------------------------------------------------------- /Geeks For Geeks/Arrays/Searching/101-Linear_Search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int search(int arr[], int n, int x){ 6 | int i = 0; 7 | for (i = 0; i < n; i++){ 8 | if(arr[i] == x) 9 | return i; 10 | } 11 | return -1; 12 | } 13 | 14 | int main() 15 | { 16 | int arr[] = {1,2,3,10,4,40}; 17 | int x = 40; 18 | int n = sizeof(arr) / sizeof(arr[0]); 19 | int result = search(arr,n,x); 20 | 21 | (result == -1)? cout<<"Element Not Found" : cout<<"Element found at index "< 2 | 3 | 4 | JavaScript Sandbox 5 | 6 | 7 | 8 | 9 |

    To-Do APP

    10 | 11 |
    12 | 13 | 14 |
    15 | 16 |
      17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /LeetCode/169-Majority_Element.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int majorityElement(int[] nums) { 3 | if(nums.length == 1) 4 | return nums[0]; 5 | 6 | HashMap map = new HashMap(); 7 | 8 | for(int i : nums){ 9 | if(map.containsKey(i) && map.get(i) + 1 > nums.length / 2){ 10 | return i; 11 | } 12 | else{ 13 | map.put(i, map.getOrDefault(i,0) + 1); 14 | } 15 | } 16 | return -1; 17 | } 18 | } -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0088_Merge_Sorted_Array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void merge(int[] nums1, int m, int[] nums2, int n) { 3 | int i = m - 1; 4 | int j = n - 1; 5 | int k = m + n - 1; 6 | 7 | while(i >= 0 && j >= 0){ 8 | if(nums1[i] > nums2[j]){ 9 | nums1[k--] = nums1[i--]; 10 | } 11 | else { 12 | nums1[k--] = nums2[j--]; 13 | } 14 | } 15 | 16 | while(j>=0){ 17 | nums1[k--] = nums2[j--]; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0003_Longest_Substring_Without_Repeating_Characters.js: -------------------------------------------------------------------------------- 1 | var lengthOfLongestSubstring = function(s) { 2 | let n = s.length; 3 | let res = 0; 4 | 5 | for(let i = 0 ; i < n ; i++){ 6 | let visited = new Array(256).fill(false) 7 | 8 | for(let j = i; j < n; j++){ 9 | if(visited[s.charCodeAt(j)] === true){ 10 | break 11 | } else { 12 | res = Math.max(res, j - i + 1); 13 | visited[s.charCodeAt(j)] = true 14 | } 15 | } 16 | } 17 | return res 18 | }; -------------------------------------------------------------------------------- /HackerRank/JAVA/JavaLoops1.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Solution { 10 | 11 | 12 | 13 | private static final Scanner sc = new Scanner(System.in); 14 | 15 | public static void main(String[] args) { 16 | int n = sc.nextInt(); 17 | 18 | for(int i = 1; i<=10; i++){ 19 | System.out.println(n + " x " + i + " = " + n*i); 20 | } 21 | 22 | sc.close(); 23 | } 24 | } -------------------------------------------------------------------------------- /HackerRank/JAVA/JavaStdinAndStdoutI.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | Scanner scan = new Scanner(System.in); 7 | int a = scan.nextInt(); 8 | int b = scan.nextInt(); 9 | int c = scan.nextInt(); 10 | scan.close(); 11 | // Complete this line 12 | // Complete this line 13 | 14 | System.out.println(a); 15 | System.out.println(b); 16 | System.out.println(c); 17 | 18 | // Complete this line 19 | // Complete this line 20 | } 21 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Must Do DSA/Power_Of_Two_Check.js: -------------------------------------------------------------------------------- 1 | function isPowerOfTwo(n){ 2 | if (n < 1){ 3 | return false 4 | } 5 | 6 | while(n > 1) { 7 | if (n % 2 !== 0) { 8 | return false; 9 | } 10 | 11 | n = n / 2; 12 | } 13 | 14 | return true; 15 | } 16 | 17 | console.log(isPowerOfTwo(5)) 18 | console.log(isPowerOfTwo(16)) 19 | 20 | // Using Bitwise Operator 21 | 22 | function isPowerOfTwoBitWise(n) { 23 | if (n < 1){ 24 | return false; 25 | } 26 | 27 | return (n & (n - 1)) === 0; 28 | } 29 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Interview Exp/CompressString.js: -------------------------------------------------------------------------------- 1 | function compressedString(str) { 2 | if (!str) { 3 | return ""; 4 | } 5 | 6 | let compressed = ""; 7 | let count = 1; 8 | 9 | for (let i = 0; i < str.length; i++) { 10 | const currentChar = str[i]; 11 | const nextChar = str[i + 1]; 12 | 13 | if (currentChar === nextChar) { 14 | count += 1; 15 | } else { 16 | compressed += currentChar + count; 17 | count = 1; 18 | } 19 | } 20 | 21 | return compressed; 22 | } 23 | 24 | console.log(compressedString("aaabbccc")); // Output: "a3b2c3" 25 | -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0028_Find_Index_First_Occurrence_String.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int strStr(String haystack, String needle) { 3 | if(needle.isEmpty()){ 4 | return 0; 5 | } 6 | 7 | int haystackLength = haystack.length() ; 8 | int needleLength = needle.length(); 9 | 10 | for(int i = 0; i <= haystackLength - needleLength; i++){ 11 | if(haystack.substring(i, i+needleLength).equals(needle)){ 12 | return i; 13 | } 14 | } 15 | 16 | return -1; 17 | 18 | } 19 | } -------------------------------------------------------------------------------- /HackerRank/JAVA/JavaStdinAndStdoutII.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | Scanner scan = new Scanner(System.in); 7 | int i = scan.nextInt(); 8 | double d = scan.nextDouble(); 9 | 10 | scan.nextLine(); 11 | String s = scan.nextLine(); 12 | scan.close(); 13 | 14 | // Write your code here. 15 | 16 | System.out.println("String: " + s); 17 | System.out.println("Double: " + d); 18 | System.out.println("Int: " + i); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /LeetCode/724-Find_Pivot_Index.java: -------------------------------------------------------------------------------- 1 | // Solution : https://www.youtube.com/watch?v=0PiH6Beqif8 2 | 3 | class Solution { 4 | public int pivotIndex(int[] nums) { 5 | int total_sum = 0; 6 | for(int i =0; i < nums.length; i++){ 7 | total_sum += nums[i]; 8 | } 9 | int left_sum = 0; 10 | for(int i = 0; i < nums.length ; i++) 11 | { 12 | if(i != 0 ) left_sum += nums[i-1]; 13 | if(total_sum - left_sum - nums[i] == left_sum) 14 | return i; 15 | 16 | } 17 | return -1; 18 | } 19 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0278_First_Bad_Version.js: -------------------------------------------------------------------------------- 1 | var solution = function(isBadVersion) { 2 | /** 3 | * @param {integer} n Total versions 4 | * @return {integer} The first bad version 5 | */ 6 | return function(n) { 7 | let start = 1; 8 | let end = n; 9 | 10 | while (start <= end){ 11 | let mid = Math.floor((start + end) / 2) 12 | 13 | if (isBadVersion(mid)) { 14 | end = mid -1 ; 15 | } else { 16 | start = mid + 1; 17 | } 18 | } 19 | return start; 20 | }; 21 | }; -------------------------------------------------------------------------------- /LeetCode/019-Remove_Nth_Node_From_End.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public ListNode removeNthFromEnd(ListNode head, int n) { 3 | ListNode start = new ListNode(); 4 | start.next = head; 5 | ListNode fast = start; 6 | ListNode slow = start; 7 | 8 | for(int i = 1; i <= n ; ++i){ 9 | fast = fast.next; 10 | } 11 | 12 | while(fast.next != null){ 13 | fast = fast.next; 14 | slow = slow.next; 15 | } 16 | 17 | slow.next = slow.next.next; 18 | 19 | return start.next; 20 | } 21 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0021_Merge_Two_Sorted_Lists.js: -------------------------------------------------------------------------------- 1 | var mergeTwoLists = function(list1, list2) { 2 | let curr = new ListNode(); 3 | const ans = curr 4 | 5 | while(list1 && list2){ 6 | if(list1.val < list2.val){ 7 | curr.next = list1 8 | list1 = list1.next 9 | } else { 10 | curr.next = list2 11 | list2 = list2.next 12 | } 13 | curr = curr.next 14 | } 15 | 16 | if (list1) { 17 | curr.next = list1; 18 | } 19 | if(list2) { 20 | curr.next = list2 21 | } 22 | 23 | return ans.next 24 | }; -------------------------------------------------------------------------------- /CodeForces/B-Teams_Forming.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.Arrays; 3 | 4 | 5 | public class Main 6 | { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | int n = sc.nextInt(); 10 | int a[] = new int[n]; 11 | int count = 0; 12 | for(int i = 0; i < n; i++){ 13 | a[i] = sc.nextInt(); 14 | } 15 | Arrays.sort(a); 16 | for(int i = 0 ; i < n-1 ; i++){ 17 | count += a[i+1] - a[i]; 18 | i++; 19 | } 20 | System.out.println(count); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0110_Balanced_Binary_Tree.js: -------------------------------------------------------------------------------- 1 | // https://www.geeksforgeeks.org/how-to-determine-if-a-binary-tree-is-balanced/ 2 | 3 | 4 | function height (root) { 5 | if (root == null) 6 | return 0; 7 | return Math.max(height(root.left), height(root.right)) + 1; 8 | } 9 | 10 | var isBalanced = function(root) { 11 | if (root == null) 12 | return true 13 | 14 | let lh = height(root.left) 15 | let rh = height(root.right) 16 | 17 | if (Math.abs(lh - rh) <= 1 && isBalanced(root.left) && isBalanced(root.right)) 18 | return true 19 | 20 | return false 21 | }; -------------------------------------------------------------------------------- /BigFrontEnd/DSA /Interview Exp/Flatten_Obj.js: -------------------------------------------------------------------------------- 1 | function flattenObject(obj) { 2 | let result = []; 3 | 4 | function recurse(current) { 5 | for (let key in current) { 6 | if (typeof current[key] === "object" && current[key] !== null) { 7 | recurse(current[key]); 8 | } else { 9 | result.push(current[key]); 10 | } 11 | } 12 | } 13 | 14 | recurse(obj); 15 | return result; 16 | } 17 | 18 | let obj1 = { a: 1, b: "string", c: { d: "x", e: 8 }, f: false }; 19 | let flattenedArray = flattenObject(obj1); 20 | console.log(flattenedArray); // Output: [1, "string", { d: "x", e: 8 }, false] 21 | -------------------------------------------------------------------------------- /LeetCode/035-Search_Insert_Position.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int searchInsert(int[] nums, int target) { 3 | int left = 0; 4 | int right = nums.length - 1; 5 | 6 | while(left <= right){ 7 | int mid = left + (right - left)/2; 8 | if(nums[mid] == target){ 9 | return mid; 10 | } 11 | else if(nums[mid] < target){ 12 | left = mid + 1; 13 | } 14 | else{ 15 | right = mid - 1; 16 | } 17 | } 18 | return left; 19 | } 20 | } -------------------------------------------------------------------------------- /LeetCode/1047-Remove_All_Adjacent_Duplicates_In_String.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String removeDuplicates(String s) { 3 | char [] stack = new char[s.length()]; 4 | int i = 0; 5 | 6 | for(int j = 0 ; j < s.length(); j++){ 7 | char current_char = s.charAt(j); 8 | 9 | if(i > 0 && stack[i-1] == current_char){ 10 | i--; 11 | } 12 | else{ 13 | stack[i] = current_char; 14 | i+=1; 15 | } 16 | } 17 | return new String(stack, 0, i); 18 | } 19 | } -------------------------------------------------------------------------------- /HackerRank/JAVA/JavaOutputFormatting.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc=new Scanner(System.in); 7 | System.out.println("================================"); 8 | for(int i=0;i<3;i++){ 9 | String s1=sc.next(); 10 | int x=sc.nextInt(); 11 | //Complete this line 12 | System.out.printf("%-15s%03d\n", s1, x); 13 | } 14 | System.out.println("================================"); 15 | sc.close(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /React Machine Coding/Todo/AddTodo.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | export default function AddTodo({ onSubmitTodo }) { 4 | [title, setTitle] = useState(""); 5 | 6 | return ( 7 |
      8 |
      9 | setTitle(e.target.value)} 13 | /> 14 | 22 |
      23 |
      24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /LeetCode/278-First_Bad_Version.java: -------------------------------------------------------------------------------- 1 | public class Solution extends VersionControl { 2 | public int firstBadVersion(int n) { 3 | int left = 0; 4 | int right = n; 5 | 6 | while(left < right){ 7 | int midpoint = left + (right - left)/2; 8 | if(isBadVersion(midpoint)){ 9 | right = midpoint; 10 | } else { 11 | left = midpoint + 1; 12 | } 13 | } 14 | 15 | if(left == right && isBadVersion(left)){ 16 | return left; 17 | } 18 | 19 | return -1; 20 | } 21 | } -------------------------------------------------------------------------------- /LeetCode/118-Pascal_Triangle.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List> generate(int numRows) { 3 | List> res = new ArrayList>(); 4 | List row, pre = null; 5 | for(int i = 0; i < numRows; ++i){ 6 | row = new ArrayList(); 7 | for(int j = 0; j <= i; ++j) 8 | if(j == 0 || j == i) 9 | row.add(1); 10 | else 11 | row.add(pre.get(j-1) + pre.get(j)); 12 | pre = row; 13 | res.add(row); 14 | } 15 | return res; 16 | } 17 | } -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0014_Longest_Common_Prefix.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String longestCommonPrefix(String[] strs) { 3 | if(strs==null || strs.length == 0){ 4 | return ""; 5 | } 6 | 7 | String prefix = strs[0]; 8 | 9 | for(int i = 1; i < strs.length; i++){ 10 | while(strs[i].indexOf(prefix) != 0){ 11 | prefix = prefix.substring(0, prefix.length()-1); 12 | 13 | if(prefix.isEmpty()){ 14 | return ""; 15 | } 16 | } 17 | } 18 | return prefix; 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /React Machine Coding/JS Machine Coding/Stop Watch/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Sandbox 5 | 6 | 7 | 8 | 9 | 10 |
      11 |

      Stopwatch

      12 | 00:00:00 13 |
      14 | 15 | 16 | 17 |
      18 |
      19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LeetCode/283-Move_Zeroes.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void moveZeroes(int[] nums) { 3 | int n = nums.length; 4 | 5 | if(n == 0 || n == 1) 6 | return; 7 | 8 | int left = 0, right = 0; 9 | int temp; 10 | 11 | while(right < n){ 12 | if(nums[right] == 0) 13 | ++right; 14 | else{ 15 | temp = nums[left]; 16 | nums[left] = nums[right]; 17 | nums[right] = temp; 18 | ++left; 19 | ++right; 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /React Machine Coding/Star Rating/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useMemo, useRef, useState } from "react"; 2 | import StarRating from "./components/StarRating"; 3 | import "./styles.css"; 4 | 5 | export default function App() { 6 | const [currentRating, setCurrentRating] = useState(0); 7 | 8 | const handleRatingChange = (newRating) => { 9 | setCurrentRating(newRating); 10 | }; 11 | 12 | return ( 13 |
      14 |

      Hello

      15 | 20 |
      21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /Geeks For Geeks/Arrays/Searching/103-Recursive_Sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int search(int arr[], int l, int r, int x){ 6 | 7 | if(r < l) 8 | return -1; 9 | if(arr[l] == x) 10 | return l; 11 | if(arr[r] == x) 12 | return r; 13 | return search(arr, l+1, r-1, x); 14 | } 15 | 16 | int main() 17 | { 18 | int arr[] = {1,2,3,4,10,40,7,6,22}; 19 | int x = 6; 20 | int n = sizeof(arr) / sizeof(arr[0]); 21 | int result = search(arr,0,n-1,x); 22 | 23 | (result == -1)? cout<<"Element Not Found" : cout<<"Element found at index "< longest ? longest + 1 : longest; 18 | }; -------------------------------------------------------------------------------- /DSA SHEET Solution/344-Reverse_String.java: -------------------------------------------------------------------------------- 1 | // Problem URL - https://leetcode.com/problems/reverse-string/description/ 2 | // Problem Solution - https://www.youtube.com/watch?v=081zwL7ut04&list=PLzffTJx5aHaRMfFodb4O5yyi6uSA4Q3E0 3 | 4 | class Solution { 5 | public void reverseString(char[] s) { 6 | int n = s.length; 7 | reverseArray(s, 0, n-1); 8 | } 9 | static void reverseArray(char[] arr, int start, int end){ 10 | if(start > end) return; 11 | char temp = arr[start]; 12 | arr[start] = arr[end]; 13 | arr[end] = temp; 14 | 15 | reverseArray(arr, start+1, end - 1); 16 | } 17 | } -------------------------------------------------------------------------------- /React Machine Coding/useContext/App.js: -------------------------------------------------------------------------------- 1 | import { 2 | ThemeContext, 3 | ThemeProvider, 4 | } from "./components/useContext/ThemeContext"; 5 | import ThemeToggler from "./components/useContext/ThemeToggler"; 6 | import "./styles.css"; 7 | 8 | export default function App() { 9 | // const [value, setValue] = useState(0); 10 | 11 | // useEffect(() => { 12 | // setInterval(() => { 13 | // setValue((val) => val + 1); 14 | // }, 100); 15 | // }, []); 16 | 17 | return ( 18 |
      19 | 20 | 21 | 22 |
      23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /LeetCode/125-Valid_Palindrom.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPalindrome(String s) { 3 | 4 | int st = 0, en = s.length() - 1; 5 | 6 | while(st <= en){ 7 | while(st < en && !Character.isLetterOrDigit(s.charAt(st))) 8 | st++; 9 | while(st < en && !Character.isLetterOrDigit(s.charAt(en))) 10 | en--; 11 | if(st < en && Character.toLowerCase(s.charAt(st)) != Character.toLowerCase(s.charAt(en))) 12 | return false; 13 | 14 | st++; 15 | en--; 16 | } 17 | return true; 18 | } 19 | } -------------------------------------------------------------------------------- /LeetCode/203-Remove_Linked_List_Elements.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public ListNode removeElements(ListNode head, int val) { 3 | while(head != null && head.val == val){ 4 | head = head.next; 5 | } 6 | 7 | ListNode current_node = head; 8 | 9 | while(current_node != null && current_node.next != null){ 10 | if(current_node.next.val == val ){ 11 | current_node.next = current_node.next.next; 12 | } 13 | else{ 14 | current_node = current_node.next; 15 | } 16 | } 17 | 18 | return head; 19 | } 20 | } -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0167_Two_Sum_II_Input_Array_Sorted.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] twoSum(int[] numbers, int target) { 3 | int left = 0; 4 | int right = numbers.length - 1; 5 | 6 | while(left < right){ 7 | int sum = numbers[left] + numbers[right]; 8 | 9 | if(sum == target){ 10 | return new int[]{left+1, right+1}; 11 | } 12 | 13 | if(sum < target){ 14 | left++; 15 | }else{ 16 | right--; 17 | } 18 | 19 | 20 | } 21 | 22 | return new int[]{-1,-1}; 23 | } 24 | } -------------------------------------------------------------------------------- /React Machine Coding/BreadCrumb Menu/styles.css: -------------------------------------------------------------------------------- 1 | .App { 2 | font-family: sans-serif; 3 | padding: 0 20px; 4 | } 5 | 6 | .prod-grid { 7 | display: grid; 8 | grid-template-columns: 1fr 1fr 1fr; 9 | grid-gap: 20px; 10 | text-align: center; 11 | } 12 | 13 | .prod-card a { 14 | text-decoration: none; 15 | color: #333; 16 | } 17 | 18 | .prod-card img { 19 | width: 100%; 20 | height: 250px; 21 | object-fit: contain; 22 | max-height: 200px; 23 | } 24 | 25 | .bread-crumbs a { 26 | text-decoration: none; 27 | color: #111; 28 | font-weight: 600; 29 | } 30 | 31 | .bread-crumbs span { 32 | color: #333; 33 | } 34 | -------------------------------------------------------------------------------- /Daily Bytes/002-Valid_Palindrome.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPalindrome(String s) { 3 | 4 | int st = 0, en = s.length() - 1; 5 | 6 | while(st <= en){ 7 | while(st < en && !Character.isLetterOrDigit(s.charAt(st))) 8 | st++; 9 | while(st < en && !Character.isLetterOrDigit(s.charAt(en))) 10 | en--; 11 | if(st < en && Character.toLowerCase(s.charAt(st)) != Character.toLowerCase(s.charAt(en))) 12 | return false; 13 | 14 | st++; 15 | en--; 16 | } 17 | return true; 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /LeetCode/116-Populating_Next_Right_Pointers_in_Each_Node.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public Node connect(Node root) { 3 | if(root == null) return root; 4 | 5 | Node leftNode = root; 6 | 7 | while(leftNode.left != null){ 8 | Node head = leftNode; 9 | while(head!=null){ 10 | head.left.next = head.right; 11 | if(head.next != null){ 12 | head.right.next = head.next.left; 13 | } 14 | head = head.next; 15 | } 16 | leftNode = leftNode.left; 17 | } 18 | return root; 19 | } 20 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /102_Binary_Tree_Level_Order_Traversal.js: -------------------------------------------------------------------------------- 1 | var levelOrder = function(root) { 2 | if (root === null) return [] 3 | 4 | let res = [] 5 | let queue = [root] 6 | 7 | while(queue.length) { 8 | let levelArr = [] 9 | let levelSize = queue.length 10 | 11 | while (levelSize) { 12 | let current = queue.shift() 13 | 14 | if(current.left) queue.push(current.left) 15 | if(current.right) queue.push(current.right) 16 | 17 | levelArr.push(current.val) 18 | levelSize-- 19 | } 20 | 21 | res.push(levelArr) 22 | } 23 | 24 | return res 25 | }; -------------------------------------------------------------------------------- /React Machine Coding/Progress Bar/style.css: -------------------------------------------------------------------------------- 1 | /* ----------------Progress Bar ----------------- */ 2 | 3 | .progress { 4 | height: 20px; 5 | width: 500px; 6 | background-color: rgb(233, 236, 239); 7 | border: 1px solid black; 8 | border-radius: 15px; 9 | overflow: hidden; 10 | position: relative; 11 | } 12 | 13 | .progress span { 14 | position: absolute; 15 | width: 100%; 16 | display: flex; 17 | flex-direction: column; 18 | align-items: center; 19 | } 20 | 21 | .progress .color { 22 | height: 100%; 23 | /* width: 20%; */ 24 | background-color: rgb(131, 207, 17); 25 | z-index: 5; 26 | } -------------------------------------------------------------------------------- /HackerRank/JAVA/JavaLoopsII.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Solution{ 5 | public static void main(String []argh){ 6 | Scanner in = new Scanner(System.in); 7 | int t=in.nextInt(); 8 | for(int i=0;iDAILY BYTES ⚡⏩👨‍💻 2 | 3 | 4 | 5 | This repository contains all the popular competitive programming questions and interview questions. The main aim of the repository is help many other students that are prepare for interview this contains various questions of Hackerank, Codechef Data Strctures and Algorithms etc. 6 | 7 | Simple if you practice on online judges like codechef or any other like Geeks for Geeks you can add questions on this repository. This repository contains all important problems that appeared Facebook, Amazon, and Google interviews. -------------------------------------------------------------------------------- /Geeks For Geeks/Mathematical/README.md: -------------------------------------------------------------------------------- 1 | # Mathematical Algorithms 🧮 2 | 3 |

      4 | 5 | ## Prime Factorization : 6 | 7 | Following are the steps to find all prime factors. 8 | 1) While n is divisible by 2, print 2 and divide n by 2. 9 | 2) After step 1, n must be odd. Now start a loop from i = 3 to square root of n. While i divides n, print i and divide n by i. After i fails to divide n, increment i by 2 and continue. 10 | 3) If n is a prime number and is greater than 2, then n will not become 1 by above two steps. So print n if it is greater than 2. 11 | -------------------------------------------------------------------------------- /LeetCode/167-Two_Sum_II.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] twoSum(int[] numbers, int target) { 3 | 4 | int a_pointer = 0; 5 | int b_pointer = numbers.length -1; 6 | 7 | while(a_pointer < b_pointer){ 8 | int sum = numbers[a_pointer] + numbers[b_pointer]; 9 | 10 | if(sum > target){ 11 | b_pointer -= 1; 12 | } 13 | else if(sum < target){ 14 | a_pointer += 1; 15 | } 16 | else 17 | return new int[] {a_pointer+1, b_pointer+1}; 18 | } 19 | 20 | return new int[] {a_pointer+1, b_pointer+1}; 21 | } 22 | } -------------------------------------------------------------------------------- /CodeForces/B-CopyCopyCopyCopyCopy.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.Arrays; 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class Main 7 | { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while(t-- >= 1){ 12 | int n = sc.nextInt(); 13 | long a[] = new long[n]; 14 | Set distinctElements = new HashSet<>(); 15 | for(int i = 0; i < n; i++){ 16 | a[i] = sc.nextInt(); 17 | distinctElements.add(a[i]); 18 | } 19 | System.out.println(distinctElements.size()); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /LeetCode/011-Container_With_Most_Water.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxArea(int[] height) { 3 | int max_area = 0; 4 | int a_pointer = 0; 5 | int b_pointer = height.length - 1; 6 | while(a_pointer < b_pointer){ 7 | if(height[a_pointer] < height[b_pointer]){ 8 | max_area = Math.max(max_area, height[a_pointer] * (b_pointer - a_pointer)); 9 | a_pointer += 1; 10 | } 11 | else{ 12 | max_area = Math.max(max_area, height[b_pointer] * (b_pointer - a_pointer)); 13 | b_pointer -= 1; 14 | } 15 | } 16 | return max_area; 17 | } 18 | } -------------------------------------------------------------------------------- /React Machine Coding/Pokedex/styles.css: -------------------------------------------------------------------------------- 1 | .App { 2 | font-family: sans-serif; 3 | text-align: center; 4 | } 5 | 6 | /* src/App.css */ 7 | .App { 8 | font-family: sans-serif; 9 | text-align: center; 10 | padding: 20px; 11 | } 12 | 13 | .dropdown-container { 14 | margin-bottom: 20px; 15 | } 16 | 17 | .pokemon-card { 18 | border: 1px solid #ccc; 19 | border-radius: 8px; 20 | padding: 20px; 21 | max-width: 400px; 22 | margin: 20px auto; 23 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 24 | } 25 | 26 | .pokemon-card img { 27 | width: 150px; 28 | height: 150px; 29 | } 30 | 31 | .pokemon-card h2 { 32 | text-transform: capitalize; 33 | } 34 | 35 | .error { 36 | color: red; 37 | } 38 | -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/Prototypical_Inheritance.js: -------------------------------------------------------------------------------- 1 | // Prototypical Inheritance 2 | let animal = { 3 | eats: true, 4 | walk() { 5 | console.log("Animal can walk"); 6 | }, 7 | }; 8 | 9 | let herbivore = { 10 | eats: true, 11 | grass() { 12 | console.log("Animal eats veg"); 13 | }, 14 | }; 15 | 16 | // let rabbit = { 17 | // jumps: true, 18 | // }; 19 | 20 | // rabbit.__proto__ = animal; // Old Way 21 | let rabbit = Object.create(animal); 22 | 23 | console.log(rabbit.eats); 24 | console.log(rabbit.walk()); 25 | console.log(Object.getPrototypeOf(rabbit)); 26 | Object.setPrototypeOf(rabbit, herbivore); 27 | console.log(Object.getPrototypeOf(rabbit)); -------------------------------------------------------------------------------- /Geeks For Geeks/Arrays/Searching/102-Binary_Search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int search(int arr[], int l, int r, int x){ 6 | 7 | while(l <= r){ 8 | int m = l + (r-1) / 2; 9 | 10 | if(arr[m] == x) 11 | return m; 12 | if(arr[m] < x) 13 | l = m + 1; 14 | else 15 | r = m - 1; 16 | } 17 | } 18 | 19 | int main() 20 | { 21 | int arr[] = {1,2,3,4,10,40}; 22 | int x = 10; 23 | int n = sizeof(arr) / sizeof(arr[0]); 24 | int result = search(arr,0,n-1,x); 25 | 26 | (result == -1)? cout<<"Element Not Found" : cout<<"Element found at index "< target){ 15 | right = midpoint - 1; 16 | } 17 | else{ 18 | left = midpoint + 1; 19 | } 20 | } 21 | return -1; 22 | } 23 | } -------------------------------------------------------------------------------- /Product_Prep_2024/LeetCode/0189_Rotate_Array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void rotate(int[] nums, int k) { 3 | int n = nums.length; 4 | k = k % n; 5 | 6 | reverse(nums, 0, n -1); 7 | reverse(nums, 0, k - 1); 8 | reverse(nums, k, n - 1); 9 | } 10 | 11 | private void reverse(int[] nums, int start, int end){ 12 | while(start < end){ 13 | int temp = nums[start]; 14 | nums[start] = nums[end]; 15 | nums[end] = temp; 16 | 17 | end--; 18 | start++; 19 | } 20 | } 21 | } 22 | 23 | 24 | // Reverse whole array -> Reverse first K elements -> revers k to n elements -------------------------------------------------------------------------------- /React Machine Coding/Pop Up/styles.css: -------------------------------------------------------------------------------- 1 | /* --------------Pop Up------------------- */ 2 | 3 | main { 4 | text-align: center; 5 | } 6 | 7 | .pop-up { 8 | position: fixed; 9 | top: 0; 10 | left: 0; 11 | width: 100%; 12 | height: 100vh; 13 | background-color: rgba(0, 0, 0, 0.2); 14 | display: flex; 15 | justify-content: center; 16 | align-items: center; 17 | } 18 | 19 | .pop-up-inner { 20 | position: relative; 21 | padding: 32px; 22 | width: 100%; 23 | max-width: 640px; 24 | background-color: #fff; 25 | } 26 | 27 | .pop-up-close { 28 | position: absolute; 29 | top: 16px; 30 | right: 16px; 31 | } -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/useWindowSize/useWindowSize.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | 3 | export default function useWindowSize() { 4 | const [windowSize, setWindowSize] = useState({ 5 | width: undefined, 6 | height: undefined, 7 | }); 8 | 9 | useEffect(() => { 10 | function handleResize() { 11 | setWindowSize({ 12 | width: window.innerWidth, 13 | height: window.innerHeight, 14 | }); 15 | } 16 | 17 | window.addEventListener("resize", handleResize); 18 | 19 | handleResize(); 20 | 21 | return () => { 22 | window.removeEventListener("resize", handleResize); 23 | }; 24 | }, []); 25 | 26 | return windowSize; 27 | } 28 | -------------------------------------------------------------------------------- /React Machine Coding/Grid Lights/styles.css: -------------------------------------------------------------------------------- 1 | /* --------------------------Grid Light---------------------------- */ 2 | 3 | .wrapper { 4 | display: flex; 5 | align-items: center; 6 | justify-content: center; 7 | flex-direction: column; 8 | gap: 16px; 9 | } 10 | 11 | .grid { 12 | display: grid; 13 | max-width: 300px; 14 | width: 100%; 15 | padding: 20px; 16 | gap: 20px; 17 | border: 1px solid black; 18 | } 19 | 20 | .cell { 21 | background-color: transparent; 22 | border: 1px solid black; 23 | height: 0px; 24 | padding-bottom: 100%; 25 | } 26 | 27 | .cell_activated { 28 | background-color: green; 29 | } 30 | -------------------------------------------------------------------------------- /React Machine Coding/JS Machine Coding/Counter/script.js: -------------------------------------------------------------------------------- 1 | let count = 0; 2 | 3 | const countDiv = document.getElementById("count"); 4 | const incrementBtn = document.getElementById("increment"); 5 | const decrementBtn = document.getElementById("decrement"); 6 | const resetBtn = document.getElementById("reset"); 7 | 8 | function updateDisplay() { 9 | countDiv.textContent = count; 10 | } 11 | 12 | incrementBtn.addEventListener("click", function () { 13 | count++; 14 | updateDisplay(); 15 | }); 16 | 17 | decrementBtn.addEventListener("click", function () { 18 | count--; 19 | updateDisplay(); 20 | }); 21 | 22 | resetBtn.addEventListener("click", function () { 23 | count = 0; 24 | updateDisplay(); 25 | }); 26 | -------------------------------------------------------------------------------- /LeetCode/031-Next_Permutation.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void nextPermutation(int[] A) { 3 | if(A == null || A.length <= 1) return; 4 | int i = A.length - 2; 5 | while(i >= 0 && A[i] >= A[i+1]) i--; 6 | if(i >= 0){ 7 | int j = A.length - 1; 8 | while(A[j] <= A[i]) j--; 9 | swap(A, i, j); 10 | } 11 | reverse(A, i + 1, A.length - 1); 12 | } 13 | 14 | public void swap(int[] A, int i, int j){ 15 | int temp = A[i]; 16 | A[i] = A[j]; 17 | A[j] = temp; 18 | } 19 | 20 | public void reverse(int[] A, int i, int j){ 21 | while(i < j) swap(A, i++, j--); 22 | } 23 | } -------------------------------------------------------------------------------- /React Machine Coding/Stop Watch/styles.css: -------------------------------------------------------------------------------- 1 | /* -------------------------- Timer -------------------------- */ 2 | 3 | .timer { 4 | width: 100%; 5 | height: 100vh; 6 | text-align: center; 7 | background-color: rgb(12, 3, 44); 8 | color: rgb(234, 234, 255); 9 | display: flex; 10 | justify-content: center; 11 | flex-direction: column; 12 | align-items: center; 13 | } 14 | 15 | .time { 16 | font-size: 100px; 17 | margin-bottom: 40px; 18 | } 19 | 20 | .control { 21 | display: flex; 22 | align-items: center; 23 | } 24 | 25 | .button { 26 | padding: 10px 20px; 27 | font-weight: 500 !important; 28 | margin-right: 10px; 29 | } -------------------------------------------------------------------------------- /CodeForces/A-Watermelon.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Watermelon{ 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int w = sc.nextInt(); 7 | int a_pointer = 2, b_pointer = w - 2; 8 | 9 | if( w <= 2) 10 | System.out.println("NO"); 11 | else if( w % 2 == 0){ 12 | while(a_pointer <= b_pointer){ 13 | if(a_pointer + b_pointer == w){ 14 | System.out.println("YES"); 15 | break; 16 | } 17 | b_pointer-=2; 18 | } 19 | } 20 | else 21 | System.out.println("NO"); 22 | } 23 | } -------------------------------------------------------------------------------- /LeetCode/496-Next_Greater_Element_I.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] nextGreaterElement(int[] nums1, int[] nums2) { 3 | HashMap next_greatest = new HashMap(); 4 | 5 | Stack stack = new Stack(); 6 | 7 | for(Integer num : nums2){ 8 | while(!stack.isEmpty() && stack.peek() < num){ 9 | next_greatest.put(stack.pop(), num); 10 | } 11 | 12 | stack.push(num); 13 | } 14 | 15 | for(int i = 0; i { 6 | return ( 7 |
      8 | {product.title} 9 |
      10 | {product.title} 11 | ${product.price} 12 |
      13 | 14 |
      15 | ); 16 | }; 17 | 18 | export default ProductCard; 19 | -------------------------------------------------------------------------------- /React Machine Coding/useContext/ThemeToggler.js: -------------------------------------------------------------------------------- 1 | import React, { useContext } from "react"; 2 | import { ThemeContext } from "./ThemeContext"; 3 | 4 | const ThemeToggler = () => { 5 | const { theme, toggleTheme } = useContext(ThemeContext); 6 | 7 | return ( 8 |
      16 |

      17 | The current theme is {theme}. 18 |

      19 | 20 |
      21 | ); 22 | }; 23 | 24 | export default ThemeToggler; 25 | -------------------------------------------------------------------------------- /LeetCode/142-Linked_List_Cycle_II.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | public ListNode detectCycle(ListNode head) { 3 | if(head == null || head.next == null) 4 | return null; 5 | 6 | ListNode slow = head; 7 | ListNode fast = head; 8 | ListNode entry = head; 9 | 10 | while(fast.next!=null && fast.next.next != null){ 11 | slow = slow.next; 12 | fast = fast.next.next; 13 | if(slow == fast ){ 14 | while(slow != entry){ 15 | slow = slow.next; 16 | fast = fast.next; 17 | } 18 | return entry; 19 | } 20 | } 21 | return null; 22 | } 23 | } -------------------------------------------------------------------------------- /CodeForces/A-Way_Too_Long_Words.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Way{ 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | int n = sc.nextInt(); 7 | sc.nextLine(); 8 | 9 | int i; 10 | String[] arr = new String[n]; 11 | 12 | for(i = 0 ; i < n ; i++){ 13 | arr[i] = sc.nextLine(); 14 | } 15 | 16 | for(i= 0 ; i < n ; i++){ 17 | if(arr[i].length()>10){ 18 | System.out.println(arr[i].charAt(0)+""+(arr[i].length()-2)+""+arr[i].charAt(arr[i].length()-1)); 19 | } 20 | else 21 | System.out.println(arr[i]); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Geeks For Geeks/DSA 450/004-Move_all_negative_elements_end.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | //User function Template for Java 4 | 5 | class Solution { 6 | 7 | public void segregateElements(int arr[], int n) 8 | { 9 | // Your code goes here 10 | int a[] = new int[n]; 11 | int k = 0; 12 | for(int i = 0; i < n ; i++){ 13 | if(arr[i] >= 0){ 14 | a[k] = arr[i]; 15 | k++; 16 | } 17 | } 18 | for(int i = 0; i < n; i++){ 19 | if(arr[i] < 0){ 20 | a[k] = arr[i]; 21 | k++; 22 | } 23 | } 24 | for(int i = 0; i < n; i++){ 25 | arr[i] = a[i]; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /LeetCode/067-Add_Binary.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String addBinary(String a, String b) { 3 | StringBuilder sb = new StringBuilder(); 4 | int i = a.length() - 1; 5 | int j = b.length() - 1; 6 | int carry = 0; 7 | 8 | while(i >= 0 || j >= 0){ 9 | int sum = carry; 10 | if(i >= 0){ 11 | sum += a.charAt(i--) - '0'; 12 | } 13 | if(j >= 0){ 14 | sum += b.charAt(j--) - '0'; 15 | } 16 | 17 | sb.insert(0, sum % 2); 18 | carry = sum / 2; 19 | } 20 | 21 | if(carry > 0){ 22 | sb.insert(0, 1); 23 | } 24 | return sb.toString(); 25 | } 26 | } -------------------------------------------------------------------------------- /Daily Bytes/005-Add_Binary.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String addBinary(String a, String b) { 3 | StringBuilder sb = new StringBuilder(); 4 | int i = a.length() - 1; 5 | int j = b.length() - 1; 6 | int carry = 0; 7 | 8 | while(i >= 0 || j >= 0){ 9 | int sum = carry; 10 | if(i >= 0){ 11 | sum += a.charAt(i--) - '0'; 12 | } 13 | if(j >= 0){ 14 | sum += b.charAt(j--) - '0'; 15 | } 16 | 17 | sb.insert(0, sum % 2); 18 | carry = sum / 2; 19 | } 20 | 21 | if(carry > 0){ 22 | sb.insert(0, 1); 23 | } 24 | return sb.toString(); 25 | } 26 | } -------------------------------------------------------------------------------- /LeetCode/349-Intersection_Of_Two_Arrays.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] intersection(int[] nums1, int[] nums2) { 3 | HashSet set = new HashSet(); 4 | 5 | for(int i : nums1){ 6 | set.add(i); 7 | } 8 | 9 | HashSet intersection = new HashSet(); 10 | 11 | for(int i : nums2){ 12 | if(set.contains(i)){ 13 | intersection.add(i); 14 | } 15 | } 16 | 17 | int[] result = new int[intersection.size()]; 18 | int index = 0; 19 | 20 | for(int i : intersection){ 21 | result[index++] = i; 22 | } 23 | 24 | return result; 25 | 26 | } 27 | } -------------------------------------------------------------------------------- /Geeks For Geeks/DSA 450/008-Minimize_the_Heights_II.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int getMinDiff(int[] arr, int n, int k) { 3 | // code here 4 | Arrays.sort(arr); 5 | 6 | int ans = arr[n-1] - arr[0]; 7 | 8 | int tempmin, tempmax; 9 | tempmin = arr[0]; 10 | tempmax = arr[n - 1]; 11 | 12 | for(int i = 1; i < n; i++){ 13 | if(arr[i] - k < 0) 14 | continue; 15 | 16 | tempmin = Math.min(arr[0] + k, arr[i] - k); 17 | 18 | tempmax = Math.max(arr[i - 1] + k, arr[n - 1] - k); 19 | 20 | ans = Math.min(ans, tempmax - tempmin); 21 | } 22 | return ans; 23 | } 24 | } -------------------------------------------------------------------------------- /LeetCode/394-Decode_String.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int i = 0; 3 | public String decodeString(String s) { 4 | StringBuilder result = new StringBuilder(); 5 | while(i < s.length() && s.charAt(i) != ']'){ 6 | if(Character.isDigit(s.charAt(i))){ 7 | int k = 0; 8 | while(i < s.length() && Character.isDigit(s.charAt(i))) 9 | k = k * 10 + s.charAt(i++) - '0'; 10 | i++; 11 | String r = decodeString(s); 12 | while(k-- > 0) 13 | result.append(r); 14 | i++; 15 | }else 16 | result.append(s.charAt(i++)); 17 | } 18 | return result.toString(); 19 | } 20 | } -------------------------------------------------------------------------------- /CodeForces/A-PolycarpAndCoins.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class PolycarpAndCoins{ 4 | 5 | public static void main(String []args){ 6 | Scanner sc = new Scanner(System.in); 7 | int t = sc.nextInt(); 8 | while(t-- >= 1){ 9 | int n = sc.nextInt(); 10 | int c1, c2; 11 | if(n % 3 == 0){ 12 | c1 = n/3; 13 | c2 = n/3; 14 | } 15 | else if(n % 3 == 1){ 16 | c2 = n/3; 17 | c1 = c2 + 1; 18 | } 19 | else{ 20 | c1 = n/3; 21 | c2 = c1 + 1; 22 | } 23 | 24 | System.out.println(c1+" "+c2); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /CodeForces/B-Mahmoud_and_a_Triangle.java: -------------------------------------------------------------------------------- 1 | // https://codeforces.com/contest/766/problem/B 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int n = sc.nextInt(); 12 | int a[] = new int[n]; 13 | 14 | for(int i = 0 ; i < n ; i++){ 15 | a[i] = sc.nextInt(); 16 | } 17 | 18 | Arrays.sort(a); 19 | int yes = 0; 20 | for(int i = 2; i < n; i++){ 21 | if(a[i-1]+a[i-2]>a[i]){ 22 | yes=1; 23 | break; 24 | } 25 | } 26 | if(yes == 1){ 27 | System.out.println("YES"); 28 | } 29 | else{ 30 | System.out.println("NO"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Geeks For Geeks/DSA 450/003-Sort_an_array_of_0_1_2.java: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public static void sort012(int a[], int n) 4 | { 5 | // code here 6 | int i, j, k; 7 | i = j = 0; 8 | k = n-1; 9 | int temp; 10 | while(j <= k){ 11 | if(a[j] == 0){ 12 | temp = a[i]; 13 | a[i] = a[j]; 14 | a[j] = temp; 15 | i++; 16 | j++; 17 | } 18 | else if(a[j] == 1){ 19 | j++; 20 | } 21 | else{ 22 | temp = a[j]; 23 | a[j] = a[k]; 24 | a[k] = temp; 25 | k--; 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/Debouncing.js: -------------------------------------------------------------------------------- 1 | const btn = document.querySelector(".increment_btn"); 2 | const btnpressed = document.querySelector(".increment_pressed"); 3 | const count = document.querySelector(".increment_count"); 4 | 5 | var pressedCount = 0; 6 | var triggeredCount = 0; 7 | 8 | const myDebounce = (cb, d) => { 9 | let timer; 10 | 11 | return function (...args) { 12 | if (timer) clearTimeout(timer); 13 | timer = setTimeout(() => { 14 | cb(...args); 15 | }, d); 16 | }; 17 | }; 18 | 19 | const debouncedCount = myDebounce(() => { 20 | count.innerHTML = ++triggeredCount; 21 | }, 800); 22 | 23 | btn.addEventListener("click", () => { 24 | btnpressed.innerHTML = ++pressedCount; 25 | debouncedCount(); 26 | }); 27 | -------------------------------------------------------------------------------- /LeetCode/048-Rotate_Image.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void rotate(int[][] matrix) { 3 | for(int i = 0; i < matrix.length; i++){ 4 | for(int j = i; j< matrix[0].length; j++){ 5 | int temp = 0; 6 | temp = matrix[i][j]; 7 | matrix[i][j] = matrix[j][i]; 8 | matrix[j][i] = temp; 9 | } 10 | } 11 | 12 | for(int i = 0; i < matrix.length; i++){ 13 | for(int j = 0; j < matrix.length / 2; j++){ 14 | int temp = 0; 15 | temp = matrix[i][j]; 16 | matrix[i][j] = matrix[i][matrix.length - 1 - j]; 17 | matrix[i][matrix.length - 1 - j] = temp; 18 | } 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /LeetCode/2129-Capitalize_The_Title.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String capitalizeTitle(String title) { 3 | title = title.toLowerCase(); 4 | String words[] = title.split(" "); 5 | StringBuilder sb = new StringBuilder(); 6 | for(int i = 0; i < words.length; i++){ 7 | if(words[i].length() < 3){ 8 | sb.append(words[i] + " "); 9 | } 10 | else{ 11 | char ch = words[i].charAt(0); 12 | ch = Character.toUpperCase(ch); 13 | String new_word = ch + words[i].substring(1); 14 | sb.append(new_word + " "); 15 | } 16 | } 17 | String result = sb.toString(); 18 | return result.trim(); 19 | } 20 | } -------------------------------------------------------------------------------- /LeetCode/003-Longest_Substring_Without_Repeating_Characters.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int lengthOfLongestSubstring(String s) { 3 | int a_pointer = 0; 4 | int b_pointer = 0; 5 | int max = 0; 6 | 7 | HashSet hash_set = new HashSet(); 8 | 9 | while(b_pointer < s.length()){ 10 | if(!hash_set.contains(s.charAt(b_pointer))){ 11 | hash_set.add(s.charAt(b_pointer)); 12 | b_pointer++; 13 | max = Math.max(hash_set.size(), max); 14 | } 15 | else{ 16 | hash_set.remove(s.charAt(a_pointer)); 17 | a_pointer++; 18 | } 19 | } 20 | 21 | return max; 22 | } 23 | } -------------------------------------------------------------------------------- /LeetCode/387-First_Unique_Character_in_a_String.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int firstUniqChar(String s) { 3 | HashMap map = new HashMap(); 4 | for(int i = 0 ; i < s.length(); i++){ 5 | char current = s.charAt(i); 6 | if(!map.containsKey(current)){ 7 | map.put(current, i); 8 | } 9 | else{ 10 | map.put(current, -1); 11 | } 12 | } 13 | 14 | int min = Integer.MAX_VALUE; 15 | for(char c: map.keySet()){ 16 | if(map.get(c) > -1 && map.get(c) < min){ 17 | min = map.get(c); 18 | } 19 | } 20 | 21 | return min == Integer.MAX_VALUE ? -1 : min; 22 | } 23 | } -------------------------------------------------------------------------------- /LeetCode/733-Flood_Fill.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[][] floodFill(int[][] image, int sr, int sc, int newColor) { 3 | if(image[sr][sc] == newColor) return image; 4 | fill(image, sr, sc, image[sr][sc], newColor); 5 | return image; 6 | } 7 | 8 | public void fill(int[][] image, int sr, int sc, int color, int newColor){ 9 | if(sr < 0 || sc < 0 || sr >= image.length || sc >= image[0].length || image[sr][sc] != color){ 10 | return; 11 | } 12 | image[sr][sc] = newColor; 13 | fill(image, sr - 1, sc, color, newColor); 14 | fill(image, sr + 1, sc, color, newColor); 15 | fill(image, sr, sc + 1, color, newColor); 16 | fill(image, sr, sc - 1, color, newColor); 17 | } 18 | } -------------------------------------------------------------------------------- /LeetCode/73-Set_Matrix_Zeroes.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void setZeroes(int[][] matrix) { 3 | int col0 = 1, rows = matrix.length, cols = matrix[0].length; 4 | 5 | 6 | for(int i = 0; i < rows; i++){ 7 | if(matrix[i][0] == 0) col0 = 0; 8 | 9 | for (int j = 1; j < cols; j++){ 10 | if(matrix[i][j] == 0) 11 | matrix[i][0] = matrix[0][j] = 0; 12 | } 13 | } 14 | 15 | for(int i = rows - 1; i >= 0; i--){ 16 | for(int j = cols - 1; j >= 1; j--){ 17 | if(matrix[i][0] == 0 || matrix[0][j] == 0) 18 | matrix[i][j] = 0; 19 | } 20 | if(col0 == 0) matrix[i][0] = 0; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /HackerRank/Problem Solving/110-Plus_Minus.py: -------------------------------------------------------------------------------- 1 | def difference(arr, n): 2 | 3 | # Initialize sums of diagonals 4 | d1 = 0 5 | d2 = 0 6 | 7 | for i in range(0, n): 8 | 9 | for j in range(0, n): 10 | 11 | # finding sum of primary diagonal 12 | if (i == j): 13 | d1 += arr[i][j] 14 | 15 | # finding sum of secondary diagonal 16 | if (i == n - j - 1): 17 | d2 += arr[i][j] 18 | 19 | # Absolute difference of the sums 20 | # across the diagonals 21 | print(abs(d1 - d2)) 22 | 23 | 24 | 25 | n = int(input().strip()) 26 | 27 | arr = [] 28 | 29 | for _ in range(n): 30 | arr.append(list(map(int, input().rstrip().split()))) 31 | difference(arr,n) -------------------------------------------------------------------------------- /LeetCode/141-Linked_List_Cycle.java: -------------------------------------------------------------------------------- 1 | // This question is asked by Microsoft. Given a linked list, containing unique numbers, return whether or not it has a cycle. 2 | // Note: a cycle is a circular arrangement (i.e. one node points back to a previous node) 3 | 4 | public class Solution { 5 | public boolean hasCycle(ListNode head) { 6 | if(head == null || head.next == null){ 7 | return false; 8 | } 9 | 10 | ListNode fast = head; 11 | ListNode slow = head; 12 | 13 | while(fast.next != null && fast.next.next != null){ 14 | fast = fast.next.next; 15 | slow = slow.next; 16 | if(fast == slow){ 17 | return true; 18 | } 19 | } 20 | 21 | return false; 22 | } 23 | } -------------------------------------------------------------------------------- /HackerRank/Problem Solving/109-Diagonal_Difference.py: -------------------------------------------------------------------------------- 1 | def difference(arr, n): 2 | 3 | # Initialize sums of diagonals 4 | d1 = 0 5 | d2 = 0 6 | 7 | for i in range(0, n): 8 | 9 | for j in range(0, n): 10 | 11 | # finding sum of primary diagonal 12 | if (i == j): 13 | d1 += arr[i][j] 14 | 15 | # finding sum of secondary diagonal 16 | if (i == n - j - 1): 17 | d2 += arr[i][j] 18 | 19 | # Absolute difference of the sums 20 | # across the diagonals 21 | print(abs(d1 - d2)) 22 | 23 | 24 | 25 | n = int(input().strip()) 26 | 27 | arr = [] 28 | 29 | for _ in range(n): 30 | arr.append(list(map(int, input().rstrip().split()))) 31 | difference(arr,n) -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0033_Search_in_Sorted_Array.js: -------------------------------------------------------------------------------- 1 | var search = function(nums, target) { 2 | let left = 0; 3 | let n = nums.length; 4 | let right = n - 1; 5 | while(left <= right){ 6 | let mid = Math.floor((left + right)/2) 7 | 8 | if(nums[mid] === target) return mid; 9 | else if(nums[mid] >= nums[left]) { 10 | if(target >= nums[left] && target < nums[mid]){ 11 | right = mid - 1 12 | } 13 | else { 14 | left = mid + 1 15 | } 16 | } 17 | else { 18 | if(target > nums[mid] && target <= nums[right]){ 19 | left = mid + 1; 20 | } else { 21 | right = mid - 1 22 | } 23 | } 24 | } 25 | return -1; 26 | }; -------------------------------------------------------------------------------- /Dot Net Repository /DSA C#/CheckPrimeNumber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class PrimeChecker 4 | { 5 | public static void Main(string[] args) 6 | { 7 | int number = 29; 8 | 9 | if (IsPrime(number)) 10 | { 11 | Console.WriteLine($"{number} is a prime number."); 12 | } 13 | else 14 | { 15 | Console.WriteLine($"{number} is not a prime number."); 16 | } 17 | } 18 | 19 | public static bool IsPrime(int number) 20 | { 21 | if (number <= 1) 22 | { 23 | return false; 24 | } 25 | 26 | for (int i = 2; i < number; i++) 27 | { 28 | if (number % i == 0) 29 | { 30 | return false; 31 | } 32 | } 33 | return true; 34 | } 35 | } -------------------------------------------------------------------------------- /React Machine Coding/File Manager/components/Folder.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | export default function Folder({ explorer }) { 4 | const [expand, setExpand] = useState(false); 5 | 6 | console.log(explorer); 7 | 8 | if (explorer.isFolder) { 9 | return ( 10 |
      11 |
      setExpand(!expand)} style={{ cursor: "pointer" }}> 12 | 🗂️ {explorer.name} 13 |
      14 | {expand && ( 15 |
      16 | {explorer.items.map((exp) => ( 17 |
      18 | 19 |
      20 | ))} 21 |
      22 | )} 23 |
      24 | ); 25 | } else { 26 | return
      📒 {explorer.name}
      ; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Geeks For Geeks/Arrays/Rotation/101-Array_Rotation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void leftRotateOne(int arr[], int n){ 6 | int temp = arr[0], i; 7 | 8 | for(i=0;i { 5 | try { 6 | const item = window.localStorage.getItem(key); 7 | return item ? JSON.parse(item) : initialValue; 8 | } catch (error) { 9 | console.error(`Error reading localStorage key "${key}":`, error); 10 | return initialValue; 11 | } 12 | }); 13 | 14 | useEffect(() => { 15 | try { 16 | window.localStorage.setItem(key, JSON.stringify(storedValue)); 17 | } catch (error) { 18 | console.error(`Error reading localStorage key "${key}":`, error); 19 | } 20 | }, [key, storedValue]); 21 | 22 | return [storedValue, setStoredValue]; 23 | } 24 | -------------------------------------------------------------------------------- /HackerRank/JAVA/JavaIfElse.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Solution { 10 | 11 | 12 | 13 | private static final Scanner scanner = new Scanner(System.in); 14 | 15 | public static void main(String[] args) { 16 | int n = scanner.nextInt(); 17 | 18 | String ans = ""; 19 | 20 | if (n%2 == 1){ 21 | ans = "Weird"; 22 | } else { 23 | if( n >= 6 && n <=20){ 24 | ans = "Weird"; 25 | } 26 | else{ 27 | ans = "Not Weird"; 28 | } 29 | } 30 | 31 | System.out.println(ans); 32 | 33 | scanner.close(); 34 | } 35 | } -------------------------------------------------------------------------------- /React Machine Coding/BreadCrumb Menu/pages/product-detail.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import { useParams } from "react-router-dom"; 3 | 4 | export default function ProductDetail() { 5 | const [product, setProduct] = useState(null); 6 | const { id } = useParams(); 7 | 8 | useEffect(() => { 9 | fetch(`https://dummyjson.com/products/${id}`) 10 | .then((res) => res.json()) 11 | .then((data) => { 12 | setProduct(data); 13 | }); 14 | }, []); 15 | 16 | return ( 17 |
      18 | {product ? ( 19 |
      20 | 21 |

      {product.description}

      22 |
      {product.price}
      23 |
      24 | ) : ( 25 |

      Loading...

      26 | )} 27 |
      28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /HackerRank/Problem Solving/105-Utopian_Tree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | 7 | int main() 8 | { 9 | int n, arr[n], x[n], i , j, m = 1; 10 | cin>>n; 11 | for(i = 0 ; i < n; i ++){ 12 | cin>>arr[i]; 13 | } 14 | 15 | for(i = 0 ; i < n; i ++){ 16 | if(arr[i]==0){ 17 | x[i] = 1; 18 | } 19 | else{ 20 | m = 1; 21 | for(j = 1 ; j <= arr[i]; j++){ 22 | if(j % 2 != 0){ 23 | m = m * 2; 24 | } 25 | else{ 26 | m = m + 1; 27 | } 28 | } 29 | x[i] = m; 30 | 31 | } 32 | 33 | } 34 | 35 | for(i = 0 ; i < n; i ++){ 36 | cout< { 4 | const [intersectionEntry, setIntersectionEntry] = useState(null); 5 | 6 | useEffect(() => { 7 | if (ref.current && typeof IntersectionObserver === "function") { 8 | const handler = (entries) => { 9 | setIntersectionEntry(entries[0]); 10 | }; 11 | 12 | const observer = new IntersectionObserver(handler, options); 13 | 14 | observer.observe(ref.current); 15 | 16 | return () => { 17 | setIntersectionEntry(null); 18 | observer.disconnect(); 19 | }; 20 | } 21 | }, [ref, options]); 22 | 23 | return intersectionEntry; 24 | }; 25 | 26 | export default useIntersectionObsever; 27 | -------------------------------------------------------------------------------- /Weekly-DSA/Week2/README.md: -------------------------------------------------------------------------------- 1 |

      Week 2

      2 | 3 | ### [Bubble Sort an Array](https://www.geeksforgeeks.org/bubble-sort/) 4 | 5 | ### [Selection Sort in an Array](https://www.geeksforgeeks.org/selection-sort/) 6 | 7 | 8 | ### [Insertion Sort in an Array](https://www.geeksforgeeks.org/insertion-sort/) 9 | 10 | ### [Merge Sort in An Array](https://www.geeksforgeeks.org/merge-sort/) 11 | 12 | ### [Quick Sort in an Array.](https://www.geeksforgeeks.org/quick-sort/) 13 | 14 | ### [Sorting of array consisting of Element 0s,1s,2s only](https://www.geeksforgeeks.org/sort-an-array-of-0s-1s-and-2s/) 15 | 16 | 17 | 18 | Medium 19 | Given an array which consists of 0,1 and 2 only. Sort the array wwithout any sorting algo. 20 | Move all the negative elements to one side of the array. 21 | Find the union and intersection of two sorted arrays. -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/useFetch/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import useFetch from "./hooks/useFetch"; 3 | import "./styles.css"; 4 | 5 | export default function App() { 6 | const { data, loading, error } = useFetch("https://dummyjson.com/products"); 7 | 8 | if (loading) { 9 | return

      loading...

      ; 10 | } 11 | 12 | if (error) { 13 | return

      An error occured : {error}

      ; 14 | } 15 | 16 | console.log(data); 17 | 18 | return ( 19 |
      20 |

      Posts

      21 | 22 | {data && 23 | data.products?.map((d) => ( 24 |
      25 | 26 |

      {d.title}

      27 |

      {d.description}

      28 |
      29 | ))} 30 |
      31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/useDebounce/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import useDebounce from "./hooks/useDebounce"; 3 | import useFetch from "./hooks/useFetch"; 4 | import "./styles.css"; 5 | 6 | export default function App() { 7 | const [input, setInput] = useState(); 8 | 9 | const handleChange = (e) => { 10 | setInput(e.target.value); 11 | }; 12 | 13 | const deboucedValue = useDebounce(input, 2000, () => { 14 | // API call logic 15 | console.log("Event Debounced"); 16 | }); 17 | 18 | return ( 19 |
      20 |

      debouncing

      21 |

      {deboucedValue}

      22 | 23 | 29 |
      30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /React Machine Coding/Pop Up/PopUp.js: -------------------------------------------------------------------------------- 1 | import { useState, useEffect } from "react"; 2 | import Pop from "./Pop"; 3 | 4 | export default function PopUp() { 5 | const [btnPopUp, setBtnPopUp] = useState(false); 6 | const [timePopUp, setTimePopUp] = useState(false); 7 | 8 | useEffect(() => { 9 | setTimeout(() => { 10 | setTimePopUp(true); 11 | }, 3000); 12 | }, []); 13 | 14 | return ( 15 |
      16 |
      17 |

      Welcome to React Pop Up

      18 | 19 | 20 | Hello from My Pop Up 21 | 22 | 23 | 24 | Hello from Timed Pop Up 25 | 26 |
      27 |
      28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /BigFrontEnd/React JS Concept Snippets/react.memo.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | 3 | const Counter = ({ count }) => { 4 | console.log("Counter Re-rendered"); 5 | return

      Count : {count}

      ; 6 | }; 7 | 8 | const MemoizedCounter = React.memo(Counter); 9 | 10 | const ReactMemo = () => { 11 | const [count, setCount] = useState(0); 12 | const [text, setText] = useState(""); 13 | 14 | return ( 15 |
      16 | {/* */} 17 | 18 | 21 | 22 | setText(e.target.value)} 26 | /> 27 |
      28 | ); 29 | }; 30 | 31 | export default ReactMemo; 32 | -------------------------------------------------------------------------------- /LeetCode/021-Merge_Two_Sorted_Lists.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public ListNode mergeTwoLists(ListNode l1, ListNode l2) { 3 | ListNode temp_node = new ListNode(0); 4 | ListNode current_node = temp_node; 5 | 6 | while(l1 != null && l2 != null){ 7 | if(l1.val < l2.val){ 8 | current_node.next = l1; 9 | l1 = l1.next; 10 | } 11 | else{ 12 | current_node.next = l2; 13 | l2 = l2.next; 14 | } 15 | current_node = current_node.next; 16 | } 17 | if(l1 != null){ 18 | current_node.next = l1; 19 | l1 = l1.next; 20 | } 21 | if(l2 != null){ 22 | current_node.next = l2; 23 | l2 = l2.next; 24 | } 25 | 26 | return temp_node.next; 27 | } 28 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0015_3Sum.js: -------------------------------------------------------------------------------- 1 | var threeSum = function(nums) { 2 | if(nums.length === 0) return []; 3 | 4 | nums = nums.sort((a, b) => a - b) 5 | let res = [] 6 | 7 | for(let i = 0; i < nums.length - 2; i++){ 8 | if(i>0 && nums[i]===nums[i-1]) continue 9 | 10 | let j = i + 1 11 | let k = nums.length - 1 12 | 13 | while( j < k){ 14 | let sum = nums[i] + nums[j] + nums[k] 15 | 16 | if(sum === 0) { 17 | res.push([nums[i], nums[j], nums[k]]) 18 | 19 | while(nums[j] === nums[j+1]) j++ 20 | while(nums[k] === nums[k+1]) k-- 21 | 22 | j++ 23 | k-- 24 | } else if (sum < 0) { 25 | j++ 26 | } else { 27 | k-- 28 | } 29 | } 30 | } 31 | 32 | return res 33 | }; 34 | -------------------------------------------------------------------------------- /HackerRank/Problem Solving/103-Cats_and_a_Mouse.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | 7 | 8 | int main() 9 | { 10 | int n, i , j, arr[100][3] ; 11 | 12 | cin>> n; 13 | 14 | for(i = 0 ; i < n ; i++){ 15 | for(j = 0 ; j < 3 ; j++){ 16 | cin>>arr[i][j]; 17 | } 18 | } 19 | 20 | i = 0; 21 | while(i diff2){ 33 | cout<<"Cat B"<<"\n"; 34 | } 35 | else{ 36 | cout<<"Mouse C"; 37 | } 38 | 39 | i++; 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /React Machine Coding/BreadCrumb Menu/components/BreadCrumb.js: -------------------------------------------------------------------------------- 1 | import { Link, useLocation } from "react-router-dom"; 2 | 3 | export default function BreadCrumb() { 4 | const { pathname } = useLocation(); 5 | const pathnames = pathname.split("/").filter((x) => x); 6 | let breadcrumbpath = ""; 7 | return ( 8 |
      9 | {pathnames.length > 0 && Home} 10 | 11 | {pathnames.map((name, index) => { 12 | breadcrumbpath += `/${name}`; 13 | const isLast = index === pathnames.length - 1; 14 | 15 | return isLast ? ( 16 | / {name} 17 | ) : ( 18 | 19 | / {name} 20 | 21 | ); 22 | })} 23 |
      24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0023_Merge_k_Sorted_Lists.js: -------------------------------------------------------------------------------- 1 | function mergeList(a, b){ 2 | let dummy = new ListNode(0) 3 | let current = dummy 4 | 5 | while(a !== null && b !== null){ 6 | if(a.val < b.val){ 7 | current.next = a; 8 | a = a.next 9 | } else { 10 | current.next = b; 11 | b = b.next; 12 | } 13 | 14 | current = current.next; 15 | } 16 | 17 | current.next = a || b; 18 | 19 | return dummy.next; 20 | } 21 | 22 | 23 | var mergeKLists = function(lists) { 24 | if(lists.length === 0){ 25 | return null; 26 | } 27 | 28 | while(lists.length > 1){ 29 | let a = lists.shift(); 30 | let b = lists.shift(); 31 | 32 | let mergeAB = mergeList(a , b) 33 | lists.push(mergeAB) 34 | } 35 | 36 | return lists[0]; 37 | }; -------------------------------------------------------------------------------- /CodeForces/A-Cards_Of_Friends.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class HelloWorld{ 4 | 5 | public static void main(String []args){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | int t = sc.nextInt(); 9 | 10 | while(t-- >= 1){ 11 | int w = sc.nextInt(); 12 | int h = sc.nextInt(); 13 | int n = sc.nextInt(); 14 | int sheets = 1; 15 | 16 | while (w % 2 == 0) { 17 | w = w / 2; 18 | sheets = sheets * 2; 19 | } 20 | while (h % 2 == 0) { 21 | h = h/2; 22 | sheets = sheets*2; 23 | } 24 | if(sheets>=n){ 25 | System.out.println("YES"); 26 | }else{ 27 | System.out.println("NO"); 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /DSA SHEET Solution/GFG-Move_All_Negative_Elements_to_End.java: -------------------------------------------------------------------------------- 1 | // Problem URL - https://practice.geeksforgeeks.org/problems/move-all-negative-elements-to-end1813/1 2 | // Solution URL - https://www.geeksforgeeks.org/move-ve-elements-end-order-extra-space-allowed/ 3 | 4 | 5 | class Solution { 6 | 7 | public void segregateElements(int arr[], int n) 8 | { 9 | int temp[] = new int[n]; 10 | int j = 0; 11 | 12 | for(int i = 0; i < n; i++){ 13 | if(arr[i]>=0) 14 | temp[j++] = arr[i]; 15 | } 16 | 17 | if (j == n || j == 0) 18 | return; 19 | 20 | for(int i = 0; i < n; i++){ 21 | if(arr[i]<0) 22 | temp[j++] = arr[i]; 23 | } 24 | 25 | for (int i = 0; i < n; i++) 26 | arr[i] = temp[i]; 27 | } 28 | } -------------------------------------------------------------------------------- /HackerRank/Problem Solving/101-Migratory_Birds.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | 7 | 8 | int main() 9 | { 10 | int n, arr[100], x[5] = {0,0,0,0,0}, i; 11 | cin>>n; 12 | 13 | for(i = 0; i < n; i++){ 14 | cin>>arr[i]; 15 | } 16 | 17 | for(i = 0; i < n ; i++){ 18 | int count = 0; 19 | int y = arr[i]; 20 | for(int j = 0; j < n ; j++){ 21 | if(arr[i] == arr[j]){ 22 | count++; 23 | } 24 | } 25 | x[y-1] = count; 26 | } 27 | 28 | int max = x[0], result = 0; 29 | 30 | for(i = 1; i=max){ 32 | max = x[i]; 33 | } 34 | } 35 | 36 | for(i = 0; i < n; i++){ 37 | if(x[i] == max){ 38 | result = i + 1; 39 | break; 40 | } 41 | } 42 | 43 | cout< 16 | 17 | 18 | 19 | } /> 20 | } /> 21 | 22 | 23 | 24 | ); 25 | } 26 | 27 | export default App; 28 | -------------------------------------------------------------------------------- /LeetCode/020-Valid_Parentheses.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isValid(String s) { 3 | if(s.length() % 2 != 0) return false; 4 | 5 | Stack stack = new Stack(); 6 | for(char c : s.toCharArray()){ 7 | if(c == '(' || c == '{' || c == '['){ 8 | stack.push(c); 9 | } 10 | else if (c == ')' && !stack.isEmpty() && stack.peek() == '('){ 11 | stack.pop(); 12 | } 13 | else if (c == '}' && !stack.isEmpty() && stack.peek() == '{'){ 14 | stack.pop(); 15 | } 16 | else if (c == ']' && !stack.isEmpty() && stack.peek() == '['){ 17 | stack.pop(); 18 | } 19 | else{ 20 | return false; 21 | } 22 | } 23 | return stack.isEmpty(); 24 | } 25 | } -------------------------------------------------------------------------------- /CodingNinza/Problem of the Day/02_Jan-PushElementToStack.java: -------------------------------------------------------------------------------- 1 | public static Stack insertAtBottom(Stack stack, int x) { 2 | // Check if the stack is empty 3 | if (stack.isEmpty()) { 4 | stack.push(x); 5 | return stack; 6 | } 7 | 8 | // Create a temporary stack to store popped elements 9 | Stack temp = new Stack<>(); 10 | 11 | // Pop all elements from the original stack and push them to temp 12 | while (!stack.isEmpty()) { 13 | temp.push(stack.pop()); 14 | } 15 | 16 | // Push the new element to the bottom of the original stack 17 | stack.push(x); 18 | 19 | // Push back the elements from temp to the original stack 20 | while (!temp.isEmpty()) { 21 | stack.push(temp.pop()); 22 | } 23 | 24 | return stack; 25 | } -------------------------------------------------------------------------------- /React Machine Coding/BreadCrumb Menu/pages/product-listing.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import { Link } from "react-router-dom"; 3 | 4 | export default function ProductListing() { 5 | const [products, setProducts] = useState([]); 6 | 7 | useEffect(() => { 8 | fetch("https://dummyjson.com/products") 9 | .then((res) => res.json()) 10 | .then((data) => { 11 | setProducts(data.products); 12 | }); 13 | }, []); 14 | 15 | return ( 16 |
      17 |
      18 | {products.map((prod) => ( 19 |
      20 | 21 | 22 |

      {prod.title}

      23 | 24 |
      25 | ))} 26 |
      27 |
      28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /React Machine Coding/File Manager/data/folderInfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "1", 3 | "name": "root", 4 | "isFolder": true, 5 | "items": [ 6 | { 7 | "id": "2", 8 | "name": "public", 9 | "isFolder": true, 10 | "items": [ 11 | { 12 | "id": "4", 13 | "name": "index.html", 14 | "isFolder": false 15 | }, 16 | { 17 | "id": "5", 18 | "name": "index.css", 19 | "isFolder": false 20 | }, 21 | { 22 | "id": "6", 23 | "name": "hello.html", 24 | "isFolder": false 25 | } 26 | ] 27 | }, 28 | { 29 | "id": "3", 30 | "name": "images", 31 | "isFolder": true, 32 | "items": [ 33 | { 34 | "id": "7", 35 | "name": "hey.html", 36 | "isFolder": false 37 | } 38 | ] 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0232_Implement_Queue_using_Stacks.js: -------------------------------------------------------------------------------- 1 | class MyQueue { 2 | constructor() { 3 | this.pushStack = []; 4 | this.popStack = []; 5 | } 6 | 7 | push(val) { 8 | this.pushStack.push(val) 9 | } 10 | 11 | pop() { 12 | if(!this.popStack.length){ 13 | while(this.pushStack.length){ 14 | this.popStack.push(this.pushStack.pop()); 15 | } 16 | } 17 | 18 | return this.popStack.pop(); 19 | } 20 | 21 | peek () { 22 | if (!this.popStack.length){ 23 | while (this.pushStack.length){ 24 | this.popStack.push(this.pushStack.pop()) 25 | } 26 | } 27 | 28 | return this.popStack[this.popStack.length - 1]; 29 | } 30 | 31 | empty() { 32 | return !this.pushStack.length && !this.popStack.length 33 | } 34 | } -------------------------------------------------------------------------------- /Daily Bytes/004-Correct_Capitalization.java: -------------------------------------------------------------------------------- 1 | // This question is asked by Google. Given a string, return whether or not it uses capitalization correctly. A string correctly uses capitalization if all letters are capitalized, no letters are capitalized, or only the first letter is capitalized. 2 | 3 | // Ex: Given the following strings... 4 | 5 | // "USA", return true 6 | // "Calvin", return true 7 | // "compUter", return false 8 | // "coding", return true 9 | 10 | 11 | class Solution { 12 | public boolean detectCapitalUse(String word) { 13 | int count = 0; 14 | 15 | for(int i = 0; i < word.length(); i++){ 16 | if(Character.isUpperCase(word.charAt(i))){ 17 | count++; 18 | } 19 | } 20 | 21 | return count == word.length() || count == 0 || count == 1 && Character.isUpperCase(word.charAt(0)); 22 | 23 | } 24 | } -------------------------------------------------------------------------------- /React Machine Coding/Progress Bar/ProgressBar.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | 3 | export default function ProgressBar({ value = 0 }) { 4 | const [percent, setPercent] = useState(value); 5 | 6 | useEffect(() => { 7 | setPercent(Math.min(100, Math.max(value, 0))); 8 | }, [value]); 9 | 10 | return ( 11 |
      12 | 49 ? "white" : "black" }}> 13 | {percent.toFixed()} % 14 | 15 |
      27 |
      28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /React Machine Coding/BreadCrumb Menu/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useMemo, useReducer, useRef, useState } from "react"; 2 | import "./styles.css"; 3 | import { BrowserRouter, Routes, Route } from "react-router-dom"; 4 | import Home from "./pages/home"; 5 | import ProductListing from "./pages/product-listing"; 6 | import ProductDetail from "./pages/product-detail"; 7 | import BreadCrumb from "../components/BreadCrumb"; 8 | 9 | export default function App() { 10 | return ( 11 | 12 |
      13 | {/* bread crumbs */} 14 | 15 | {/* Routes */} 16 | 17 | } /> 18 | } /> 19 | } /> 20 | 21 |
      22 |
      23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/React Hooks Polyfills/useEffect/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import "./styles.css"; 3 | 4 | export default function App() { 5 | const [counter, setCounter] = useState(0); 6 | const [counter2, setCounter2] = useState(0); 7 | 8 | const handleClick = () => { 9 | setCounter(counter + 1); 10 | }; 11 | 12 | const handleClick2 = () => { 13 | setCounter2(counter2 + 1); 14 | }; 15 | 16 | useEffect(() => { 17 | console.log("Effect Triggered", counter); 18 | 19 | return () => { 20 | console.log("clean up"); 21 | }; 22 | }, [counter]); 23 | 24 | return ( 25 |
      26 |

      {counter}

      27 | 28 | 29 |

      {counter2}

      30 | 31 |
      32 | ); 33 | } 34 | -------------------------------------------------------------------------------- /LeetCode/567-Permutation_in_String.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean checkInclusion(String s1, String s2) { 3 | int m = s1.length(); 4 | int n = s2.length(); 5 | 6 | 7 | if(n < m){ 8 | return false; 9 | } 10 | int[] freq1 = new int[26]; 11 | int[] freq2 = new int[26]; 12 | 13 | for(int i=0; i < m; i++){ 14 | freq1[s1.charAt(i) - 'a']++; 15 | freq2[s2.charAt(i) - 'a']++; 16 | } 17 | 18 | for(int i=m; i< n; i++){ 19 | if(Arrays.equals(freq1, freq2)){ 20 | return true; 21 | } 22 | freq2[s2.charAt(i) - 'a']++; 23 | freq2[s2.charAt(i-m) - 'a']--; 24 | } 25 | if(Arrays.equals(freq1, freq2)){ 26 | return true; 27 | } 28 | 29 | return false; 30 | } 31 | } -------------------------------------------------------------------------------- /Geeks For Geeks/Arrays/001-Find_the_repeating_and_the_missing.java: -------------------------------------------------------------------------------- 1 | // Link - https://www.geeksforgeeks.org/find-a-repeating-and-a-missing-number/ 2 | 3 | import java.io.*; 4 | 5 | public class Solution{ 6 | 7 | 8 | public static void main(String []args){ 9 | int[] v = { 4, 3, 6, 2, 1, 6, 7 }; 10 | 11 | int n = v.length; 12 | 13 | int sum = n * (n + 1) / 2; 14 | int sum_square = n * (n+1) * (2 * n + 1) / 6; 15 | 16 | for(int i = 0 ; i < n; i++){ 17 | sum = sum - v[i]; 18 | sum_square = sum_square - (v[i] * v[i]); 19 | } 20 | 21 | int missing = ((sum_square / sum) + sum) / 2; 22 | int repeating = missing - sum; 23 | 24 | System.out.println("Missing Number is "+ missing); 25 | System.out.println("Repeating Number is "+ repeating); 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/React Hooks Polyfills/useMemo/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useMemo, useRef, useState } from "react"; 2 | import useCustomMemo from "../components/use-custom-memo"; 3 | import "./styles.css"; 4 | 5 | export default function App() { 6 | const [counter, setCounter] = useState(0); 7 | const [counter2, setCounter2] = useState(100); 8 | 9 | const square = () => { 10 | console.log("Expensive Calculation"); 11 | return counter * counter; 12 | }; 13 | 14 | const memoizedSquare = useCustomMemo(square, [counter]); 15 | 16 | return ( 17 |
      18 |

      Square Value : {memoizedSquare}

      19 |

      Counter 1 : {counter}

      20 | 21 |

      Counter 2 : {counter2}

      22 | 23 |
      24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /LeetCode/075-Sort_Colors.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void sortColors(int[] nums) { 3 | int lo = 0; 4 | int hi = nums.length - 1; 5 | int mid = 0; 6 | 7 | int temp; 8 | 9 | while(mid <= hi){ 10 | switch(nums[mid]){ 11 | case 0 : { 12 | temp = nums[lo]; 13 | nums[lo] = nums[mid]; 14 | nums[mid] = temp; 15 | lo++; 16 | mid++; 17 | break; 18 | } 19 | case 1: 20 | mid++; 21 | break; 22 | case 2: { 23 | temp = nums[mid]; 24 | nums[mid] = nums[hi]; 25 | nums[hi] = temp; 26 | hi--; 27 | break; 28 | } 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/React Hooks Polyfills/useEffect/useCustomEffect.js: -------------------------------------------------------------------------------- 1 | import { useRef } from "react"; 2 | 3 | const useCustomHook = (cb, deps) => { 4 | const isFirstRender = useRef(true); 5 | const prevDeps = useRef([]); 6 | 7 | // First Render 8 | if (isFirstRender.current) { 9 | isFirstRender.current = false; 10 | const cleanup = cb(); 11 | 12 | return () => { 13 | if (cleanup && typeof cleanup === "function") { 14 | cleanup(); 15 | } 16 | }; 17 | } 18 | 19 | // deps changes or No deps array 20 | const depsChanged = deps 21 | ? JSON.stringify(deps) !== JSON.stringify(prevDeps.current) 22 | : true; 23 | 24 | if (depsChanged) { 25 | const cleanup = cb(); 26 | if (cleanup && typeof cleanup === "function") { 27 | cleanup(); 28 | } 29 | } 30 | 31 | prevDeps.current = deps || []; 32 | }; 33 | 34 | export default useCustomHook; 35 | -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/useFetch/useFetch.js: -------------------------------------------------------------------------------- 1 | const { useState, useEffect } = require("react"); 2 | 3 | const useFetch = (url) => { 4 | const [data, setData] = useState([]); 5 | const [loading, setLoading] = useState(false); 6 | const [error, setError] = useState(null); 7 | 8 | useEffect(() => { 9 | const fetchData = async () => { 10 | setLoading(true); 11 | 12 | try { 13 | const response = await fetch(url); 14 | if (!response.ok) { 15 | throw new Error("Server Response not OK"); 16 | } 17 | const result = await response.json(); 18 | setData(result); 19 | } catch (err) { 20 | setError(err); 21 | } finally { 22 | setLoading(false); 23 | } 24 | }; 25 | 26 | if (url) { 27 | fetchData(); 28 | } 29 | }, [url]); 30 | 31 | return { data, loading, error }; 32 | }; 33 | 34 | export default useFetch; 35 | -------------------------------------------------------------------------------- /React Machine Coding/Infinite Scrolling/InfiniteScrolling.js: -------------------------------------------------------------------------------- 1 | // Reference - https://www.youtube.com/watch?v=Ckka1HhE2kM 2 | 3 | import { useEffect, useState } from "react"; 4 | 5 | export default function InfiniteScroll() { 6 | const [count, setCount] = useState(50); 7 | 8 | useEffect(() => { 9 | const onScroll = () => { 10 | if ( 11 | window.innerHeight + window.scrollY >= 12 | window.document.body.offsetHeight - 30 13 | ) { 14 | setCount(count + 50); 15 | } 16 | }; 17 | window.addEventListener("scroll", onScroll); 18 | 19 | return () => window.removeEventListener("scroll", onScroll); 20 | }, [count]); 21 | 22 | const elements = []; 23 | 24 | for (let i = 0; i < count; i++) { 25 | elements.push(
      {i + 1}
      ); 26 | } 27 | 28 | return ( 29 |
      30 | Hello from Infinite Scroll 31 | {elements} 32 |
      33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /Dot Net Repository /DSA C#/FactorialUsingRecursion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class FactorialCalculator 4 | { 5 | public static void Main(string[] args) 6 | { 7 | int number = 5; 8 | 9 | // Check for non-negative input 10 | if (number < 0) 11 | { 12 | Console.WriteLine("Factorial of a negative number does not exist."); 13 | } 14 | else 15 | { 16 | long result = Factorial(number); 17 | Console.WriteLine($"The factorial of {number} is {result}."); 18 | } 19 | } 20 | 21 | // Recursive function to calculate factorial 22 | public static long Factorial(int n) 23 | { 24 | // Base case: 0! and 1! are both 1 25 | if (n <= 1) 26 | { 27 | return 1; 28 | } 29 | // Recursive step: n * (n-1)! 30 | else 31 | { 32 | return n * Factorial(n - 1); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /DSA SHEET Solution/075-Sort_Colors.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void sortColors(int[] nums) { 3 | int lo = 0; 4 | int mid = 0; 5 | int hi = nums.length - 1; 6 | int temp; 7 | while(mid <= hi){ 8 | switch(nums[mid]){ 9 | case 0 : { 10 | temp = nums[lo]; 11 | nums[lo] = nums[mid]; 12 | nums[mid] = temp; 13 | lo++; 14 | mid++; 15 | break; 16 | } 17 | case 1: { 18 | mid++; 19 | break; 20 | } 21 | case 2: { 22 | temp = nums[mid]; 23 | nums[mid] = nums[hi]; 24 | nums[hi] = temp; 25 | hi--; 26 | break; 27 | } 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Geeks For Geeks/Arrays/002-Leaders_In_Array.java: -------------------------------------------------------------------------------- 1 | public class LeadersInArray 2 | { 3 | /* Java Function to print leaders in an array */ 4 | void printLeaders(int arr[], int size) 5 | { 6 | int max_from_right = arr[size-1]; 7 | 8 | /* Rightmost element is always leader */ 9 | System.out.print(max_from_right + " "); 10 | 11 | for (int i = size-2; i >= 0; i--) 12 | { 13 | if (max_from_right < arr[i]) 14 | { 15 | max_from_right = arr[i]; 16 | System.out.print(max_from_right + " "); 17 | } 18 | } 19 | } 20 | 21 | /* Driver program to test above functions */ 22 | public static void main(String[] args) 23 | { 24 | LeadersInArray lead = new LeadersInArray(); 25 | int arr[] = new int[]{16, 17, 4, 3, 5, 2}; 26 | int n = arr.length; 27 | lead.printLeaders(arr, n); 28 | } 29 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0016_3Sum.js: -------------------------------------------------------------------------------- 1 | var threeSum = function(nums) { 2 | let result = []; 3 | 4 | nums.sort((a,b) => a-b) 5 | 6 | for(let i = 0; i < nums.length - 2; i++){ 7 | if(i > 0 && nums[i] === nums[i-1]) continue 8 | 9 | let left = i + 1; 10 | let right = nums.length - 1; 11 | 12 | while(left < right){ 13 | const sum = nums[i] + nums[left] + nums[right]; 14 | 15 | if(sum === 0){ 16 | result.push([nums[i], nums[left], nums[right]]) 17 | 18 | while(left < right && nums[left] == nums[left + 1]) left++; 19 | while(left < right && nums[right] == nums[right-1]) right--; 20 | 21 | left++ 22 | right-- 23 | } 24 | else if(sum < 0){ 25 | left++ 26 | } else { 27 | right-- 28 | } 29 | } 30 | } 31 | return result 32 | }; -------------------------------------------------------------------------------- /CodeForces/B-Bad_Prices.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * 5 | */ 6 | public class Problem1213B { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | int t = sc.nextInt(); 10 | while(t-->=1){ 11 | int n = sc.nextInt(); 12 | int prices[] = new int[n]; 13 | for(int i =0; i=0;i--){ 19 | if(prices[i]>min){ 20 | //we have compared that price of today is greater than the minimum value 21 | countOfBadDays++; 22 | } 23 | min = Math.min(prices[i], min); 24 | } 25 | System.out.println(countOfBadDays); 26 | } 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/Toggle.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | import useToggle from "./customHook"; 3 | 4 | export default function Toggle() { 5 | // [state, setState] = useState(false); 6 | 7 | // const handleClick = () => { 8 | // setState(!state); 9 | // }; 10 | 11 | // const handleTrue = () => { 12 | // setState(true); 13 | // }; 14 | 15 | // const handleFalse = () => { 16 | // setState(false); 17 | // }; 18 | 19 | [state, { setToggle, setTrue }] = useToggle(false); 20 | 21 | return ( 22 |
      23 |
      24 | {/* 25 | 26 | */} 27 | 28 | 29 | 30 |

      {state.toString()}

      31 |
      32 |
      33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /CodeForces/A-Odd_Set.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | 4 | public class OddSet{ 5 | 6 | public static void main(String []args){ 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int t = sc.nextInt(); 10 | 11 | while(t-- >= 1){ 12 | int n = sc.nextInt(); 13 | int size = 2 * n; 14 | int arr[] = new int[size]; 15 | 16 | int odd = 0; 17 | int even = 0; 18 | 19 | for(int i = 0 ; i < size ; i++){ 20 | arr[i] = sc.nextInt(); 21 | if(arr[i] % 2 == 0){ 22 | even++; 23 | } 24 | else{ 25 | odd++; 26 | } 27 | } 28 | 29 | if(even == odd){ 30 | System.out.println("Yes"); 31 | } 32 | else 33 | System.out.println("No"); 34 | 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0784_Letter_Case_Permutation.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} s 3 | * @return {string[]} 4 | */ 5 | var letterCasePermutation = function(S) { 6 | const result = []; 7 | 8 | const dfs = (i, S, slate) => { 9 | // base case 10 | if (i === S.length){ 11 | result.push(slate.join('')); 12 | return; 13 | } 14 | 15 | // dfs recursive case 16 | let char = S[i] 17 | 18 | if(!Number.isInteger(parseInt(char))) { 19 | // uppercase 20 | slate.push(char.toUpperCase()); 21 | dfs(i + 1, S, slate); 22 | slate.pop() 23 | 24 | // lowercase 25 | slate.push(char.toLowerCase()); 26 | dfs(i + 1, S, slate); 27 | slate.pop() 28 | } else { 29 | slate.push(char) 30 | dfs(i + 1, S, slate) 31 | slate.pop(); 32 | } 33 | } 34 | 35 | dfs(0, S, []); 36 | return result; 37 | }; -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/PromiseAllPolyfill.js: -------------------------------------------------------------------------------- 1 | function promiseAll(promiseTask) { 2 | let res = new Array(promiseTask.length); 3 | let completed = 0; 4 | 5 | return new Promise((resolve, rejects) => { 6 | for (let i = 0; i < promiseTask.length; i++) { 7 | Promise.resolve(promiseTask[i]) 8 | .then((data) => { 9 | res[i] = data; 10 | completed++; 11 | 12 | if (completed === promiseTask.length) { 13 | resolve(res); 14 | } 15 | }) 16 | .catch((error) => { 17 | reject(error); 18 | }); 19 | } 20 | }); 21 | } 22 | 23 | const promise1 = Promise.resolve(1); 24 | const promise2 = Promise.resolve(2); 25 | const promise3 = new Promise((resolve) => { 26 | setTimeout(() => { 27 | resolve(30); 28 | }, 1000); 29 | }); 30 | 31 | promiseAll([promise1, promise2, promise3]) 32 | .then((res) => { 33 | console.log(res); 34 | }) 35 | .catch((error) => console.log("One of the promise failed", error)); 36 | -------------------------------------------------------------------------------- /LeetCode/680-Valid_Palindrome_II.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean validPalindrome(String s) { 3 | int a_pointer = 0; 4 | int b_pointer = s.length() - 1; 5 | 6 | while(a_pointer <= b_pointer){ 7 | if(s.charAt(a_pointer) != s.charAt(b_pointer)){ 8 | return helperMethod(s, a_pointer+1, b_pointer) || helperMethod(s, a_pointer, b_pointer-1); 9 | } 10 | 11 | a_pointer++; 12 | b_pointer--; 13 | 14 | } 15 | 16 | return true; 17 | } 18 | 19 | public boolean helperMethod(String s, int i, int j){ 20 | int a_pointer = i; 21 | int b_pointer = j; 22 | 23 | while(a_pointer <= b_pointer){ 24 | if(s.charAt(a_pointer) != s.charAt(b_pointer)){ 25 | return false; 26 | } 27 | 28 | a_pointer++; 29 | b_pointer--; 30 | } 31 | return true; 32 | } 33 | } -------------------------------------------------------------------------------- /Daily Bytes/007-Valid_Palindrome_II.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean validPalindrome(String s) { 3 | int a_pointer = 0; 4 | int b_pointer = s.length() - 1; 5 | 6 | while(a_pointer <= b_pointer){ 7 | if(s.charAt(a_pointer) != s.charAt(b_pointer)){ 8 | return helperMethod(s, a_pointer+1, b_pointer) || helperMethod(s, a_pointer, b_pointer-1); 9 | } 10 | 11 | a_pointer++; 12 | b_pointer--; 13 | 14 | } 15 | 16 | return true; 17 | } 18 | 19 | public boolean helperMethod(String s, int i, int j){ 20 | int a_pointer = i; 21 | int b_pointer = j; 22 | 23 | while(a_pointer <= b_pointer){ 24 | if(s.charAt(a_pointer) != s.charAt(b_pointer)){ 25 | return false; 26 | } 27 | 28 | a_pointer++; 29 | b_pointer--; 30 | } 31 | return true; 32 | } 33 | } -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/useLocalStorage/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import useLocalStorage from "./components/useLocalStorage"; 3 | import "./styles.css"; 4 | 5 | export default function App() { 6 | const [user, setUser] = useLocalStorage("userName", "Guest"); 7 | const [theme, setTheme] = useLocalStorage("dark", false); 8 | 9 | return ( 10 |
      11 |

      Hello

      12 | setUser(e.target.value)} 16 | /> 17 | 18 | setTheme(e.target.checked)} 22 | /> 23 |
      24 |
      25 | 26 |
      33 |

      This content changes theme

      34 |
      35 |
      36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /Daily Bytes/001-Reverse String.java: -------------------------------------------------------------------------------- 1 | // This question is asked by Google. Given a string, reverse all of its characters and return the resulting string. 2 | 3 | // Ex: Given the following strings... 4 | 5 | // “Cat”, return “taC” 6 | // “The Daily Byte”, return "etyB yliaD ehT” 7 | // “civic”, return “civic” 8 | 9 | 10 | 11 | 12 | import java.lang.*; 13 | import java.io.*; 14 | import java.util.*; 15 | 16 | 17 | public class ReverseString{ 18 | 19 | public static void main(String []args){ 20 | String input; 21 | Scanner sc = new Scanner(System.in); 22 | System.out.println("Enter the desired String: "); 23 | input = sc.nextLine(); 24 | 25 | byte[] strAsByteArray = input.getBytes(); 26 | 27 | byte[] result = new byte[strAsByteArray.length]; 28 | 29 | for (int i = 0; i < strAsByteArray.length; i++){ 30 | result[i] = strAsByteArray[strAsByteArray.length - i - 1]; 31 | } 32 | 33 | System.out.println(new String(result)); 34 | } 35 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0121_Best_Time_To_Buy_Stock.js: -------------------------------------------------------------------------------- 1 | // JS Solution is as follows : 2 | var maxProfit = function(prices) { 3 | let min_price = prices[0]; 4 | let max_profit = 0; 5 | 6 | for(let index in prices){ 7 | if(prices[index] < min_price ){ 8 | min_price = prices[index]; 9 | } 10 | else if (prices[index] - min_price > max_profit){ 11 | max_profit = prices[index] - min_price; 12 | } 13 | } 14 | return max_profit; 15 | }; 16 | 17 | 18 | // class Solution { 19 | // public int maxProfit(int[] prices) { 20 | // int min_price = Integer.MAX_VALUE; 21 | // int max_profit = 0; 22 | 23 | // for(int i = 0; i < prices.length; i++){ 24 | // if(prices[i] < min_price){ 25 | // min_price = prices[i]; 26 | // } else if (prices[i] - min_price > max_profit){ 27 | // max_profit = prices[i] - min_price; 28 | // } 29 | // } 30 | // return max_profit; 31 | // } 32 | // } -------------------------------------------------------------------------------- /LeetCode/695-Max_Area_of_Island.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | boolean seen[][]; 3 | 4 | public int maxAreaOfIsland(int[][] grid) { 5 | int max_area = 0; 6 | 7 | int rows = grid.length; 8 | int columns = grid[0].length; 9 | 10 | seen = new boolean[rows][columns]; 11 | 12 | for(int i =0 ; i < rows; i++){ 13 | for(int j = 0; j < columns; j++){ 14 | max_area = Math.max(max_area, area(i,j,grid)); 15 | } 16 | } 17 | 18 | return max_area; 19 | } 20 | 21 | public int area(int row, int column, int[][] grid){ 22 | if(row < 0 || row >= grid.length || column < 0 || column >= grid[row].length ||seen[row][column] || (grid[row][column] == 0)){ 23 | return 0; 24 | } 25 | 26 | seen[row][column] = true; 27 | 28 | return (1 + area(row+1, column, grid) + area(row-1, column, grid) + area(row, column + 1, grid) + area(row, column - 1, grid)); 29 | } 30 | } -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/React Hooks Polyfills/useMemo/useCustomMemo.js: -------------------------------------------------------------------------------- 1 | // useMemo Polyfill 2 | 3 | import { useEffect, useRef } from "react"; 4 | 5 | const areEqual = (prevDeps, nextDeps) => { 6 | if (prevDeps === null) return false; 7 | 8 | if (prevDeps.length !== nextDeps.length) return false; 9 | 10 | for (let i = 0; i < prevDeps.length; i++) { 11 | if (prevDeps[i] !== nextDeps[i]) { 12 | return false; 13 | } 14 | } 15 | 16 | return true; 17 | }; 18 | 19 | const useCustomMemo = (cb, deps) => { 20 | // variavle or state -> to store cache value 21 | const memoizedRef = useRef(null); 22 | //changes in deps 23 | if (!memoizedRef.current || !areEqual(memoizedRef.current.deps, deps)) { 24 | memoizedRef.current = { 25 | value: cb(), 26 | deps, 27 | }; 28 | } 29 | //cleanup logic 30 | useEffect(() => { 31 | memoizedRef.current = null; 32 | }, []); 33 | // return memoized value(if any) 34 | return memoizedRef.current.value; 35 | }; 36 | 37 | export default useCustomMemo; 38 | -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/Function_Binding.js: -------------------------------------------------------------------------------- 1 | // bind - pollyfill using apply() 2 | Function.prototype.bindUsingApply = function (ctx, ...args) { 3 | let fn = this; 4 | 5 | let allArgs = args; 6 | 7 | return function (...newArgs) { 8 | allArgs = [...allArgs, ...newArgs]; 9 | return fn.apply(ctx, allArgs); 10 | }; 11 | }; 12 | 13 | // bind - polyfill without using apply() 14 | Function.prototype.bindWithoutUsingApply = function(ctx, ...args){ 15 | ctx.callableFn = this; 16 | 17 | let allArgs = args; 18 | 19 | return function (...newArgs) { 20 | allArgs = [...allArgs, ...newArgs]; 21 | return ctx.callableFn(allArgs); 22 | }; 23 | } 24 | 25 | let myName1 = printname.bindUsingApply(user, "123"); 26 | let myName = printname.bindWithoutUsingApply(user, "mohanty"); 27 | 28 | myName(); 29 | myName1(); 30 | 31 | // function print() { 32 | // console.log(this.firstname); 33 | // } 34 | 35 | // let myFunc = print.bind(user); 36 | 37 | // myFunc(); -------------------------------------------------------------------------------- /Geeks For Geeks/Linked List/002-Linked_List_Traversal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Node { 5 | public: 6 | int data; 7 | Node* next; 8 | }; 9 | 10 | // This function prints contents of linked list 11 | // starting from the given node 12 | void printList(Node* n) 13 | { 14 | while (n != NULL) { 15 | cout << n->data << " "; 16 | n = n->next; 17 | } 18 | } 19 | 20 | // Driver code 21 | int main() 22 | { 23 | Node* head = NULL; 24 | Node* second = NULL; 25 | Node* third = NULL; 26 | 27 | // allocate 3 nodes in the heap 28 | head = new Node(); 29 | second = new Node(); 30 | third = new Node(); 31 | 32 | head->data = 1; // assign data in first node 33 | head->next = second; // Link first node with second 34 | 35 | second->data = 2; // assign data to second node 36 | second->next = third; 37 | 38 | third->data = 3; // assign data to third node 39 | third->next = NULL; 40 | 41 | printList(head); 42 | 43 | return 0; 44 | } -------------------------------------------------------------------------------- /React Machine Coding/Stop Watch - useRef/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useRef, useState } from "react"; 2 | import "./styles.css"; 3 | 4 | export default function App() { 5 | const [now, setNow] = useState(null); 6 | const [startTime, setStartTime] = useState(null); 7 | let intervalRef = useRef(null); 8 | 9 | const handleStart = () => { 10 | setNow(Date.now()); 11 | setStartTime(Date.now()); 12 | 13 | clearInterval(intervalRef.current); 14 | intervalRef.current = setInterval(() => { 15 | setNow(Date.now()); 16 | }, 10); 17 | }; 18 | 19 | const handleStop = () => { 20 | clearInterval(intervalRef.current); 21 | }; 22 | 23 | let intervalTime = 0; 24 | if (now !== null && startTime !== null) { 25 | intervalTime = (now - startTime) / 1000; 26 | } 27 | 28 | return ( 29 |
      30 | {intervalTime.toFixed(3)} 31 |
      32 |
      33 | 34 | 35 |
      36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /CodeForces/A-Contest_Start.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class HelloWorld{ 4 | 5 | public static void main(String []args){ 6 | Scanner sc = new Scanner(System.in); 7 | int k = sc.nextInt(); 8 | 9 | for(int i = 0; i < k; i++){ 10 | long n = sc.nextInt(); 11 | long x = sc.nextInt(); 12 | long t = sc.nextInt(); 13 | 14 | if(t < x){ 15 | System.out.println("0"); 16 | continue; 17 | } 18 | long first = t/x; 19 | if(first >= n-1){ 20 | long ans = n - 1; 21 | ans = (ans * (ans + 1))/2; 22 | System.out.println(ans); 23 | } 24 | else{ 25 | long ans1 = first; 26 | ans1 = (ans1 * (ans1 + 1))/2; 27 | long ans2 = (n -1 - first) * first; 28 | long ansf = ans1 + ans2; 29 | System.out.println(ansf); 30 | } 31 | } 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0217_Contains_Duplicates.js: -------------------------------------------------------------------------------- 1 | // Solution 1 : Using HashSet in Java 2 | // class Solution { 3 | // public boolean containsDuplicate(int[] nums) { 4 | // HashSet numbers = new HashSet<>(); 5 | 6 | // for(int i = 0;i < nums.length; i++ ){ 7 | // if(numbers.contains(nums[i])) return true; 8 | // numbers.add(nums[i]); 9 | // } 10 | // return false; 11 | // } 12 | // } 13 | 14 | // Solution 2: Sort Array using Arrays.Sort in Java 15 | // Compare element in 1 & i+1 16 | 17 | // class Solution { 18 | // public boolean containsDuplicate(int[] nums) { 19 | // Arrays.sort(nums); 20 | 21 | // for(int i = 0; i < nums.length - 1; i++){ 22 | // if(nums[i] == nums[i+1]) return true; 23 | // } 24 | // return false; 25 | // } 26 | // } 27 | 28 | // JavaScript Solution : https://www.youtube.com/watch?v=hRt9qadriyQ 29 | 30 | var containsDuplicate = function(nums) { 31 | const set = new Set(nums); 32 | return set.size !== nums.length 33 | }; 34 | -------------------------------------------------------------------------------- /Daily Bytes/003-Vacuum_Cleaner_Route.java: -------------------------------------------------------------------------------- 1 | // This question is asked by Amazon. Given a string representing the sequence of moves a robot vacuum makes, return whether or not it will return to its original position. The string will only contain L, R, U, and D characters, representing left, right, up, and down respectively. 2 | 3 | // Ex: Given the following strings... 4 | 5 | // "LR", return true 6 | // "URURD", return false 7 | // "RUULLDRD", return true 8 | 9 | 10 | class Solution { 11 | public boolean judgeCircle(String moves) { 12 | int UD = 0; 13 | int LR = 0; 14 | 15 | for(int i = 0; i < moves.length(); i++){ 16 | char currentMove = moves.charAt(i); 17 | if(currentMove == 'U'){ 18 | UD++; 19 | } 20 | else if(currentMove == 'D'){ 21 | UD--; 22 | } 23 | else if(currentMove == 'L'){ 24 | LR++; 25 | } 26 | else{ 27 | LR--; 28 | } 29 | } 30 | 31 | return (UD == 0 && LR ==0); 32 | } 33 | } -------------------------------------------------------------------------------- /Daily Bytes/006-Robot_Return_To_Origin.java: -------------------------------------------------------------------------------- 1 | // This question is asked by Amazon. Given a string representing the sequence of moves a robot vacuum makes, return whether or not it will return to its original position. The string will only contain L, R, U, and D characters, representing left, right, up, and down respectively. 2 | 3 | // Ex: Given the following strings... 4 | 5 | // "LR", return true 6 | // "URURD", return false 7 | // "RUULLDRD", return true 8 | 9 | 10 | class Solution { 11 | public boolean judgeCircle(String moves) { 12 | int UD = 0; 13 | int LR = 0; 14 | 15 | for(int i = 0; i < moves.length(); i++){ 16 | char currentMove = moves.charAt(i); 17 | if(currentMove == 'U'){ 18 | UD++; 19 | } 20 | else if(currentMove == 'D'){ 21 | UD--; 22 | } 23 | else if(currentMove == 'L'){ 24 | LR++; 25 | } 26 | else{ 27 | LR--; 28 | } 29 | } 30 | 31 | return (UD == 0 && LR ==0); 32 | } 33 | } -------------------------------------------------------------------------------- /LeetCode/657-Robot_Return_To_Origin.java: -------------------------------------------------------------------------------- 1 | // This question is asked by Amazon. Given a string representing the sequence of moves a robot vacuum makes, return whether or not it will return to its original position. The string will only contain L, R, U, and D characters, representing left, right, up, and down respectively. 2 | 3 | // Ex: Given the following strings... 4 | 5 | // "LR", return true 6 | // "URURD", return false 7 | // "RUULLDRD", return true 8 | 9 | 10 | class Solution { 11 | public boolean judgeCircle(String moves) { 12 | int UD = 0; 13 | int LR = 0; 14 | 15 | for(int i = 0; i < moves.length(); i++){ 16 | char currentMove = moves.charAt(i); 17 | if(currentMove == 'U'){ 18 | UD++; 19 | } 20 | else if(currentMove == 'D'){ 21 | UD--; 22 | } 23 | else if(currentMove == 'L'){ 24 | LR++; 25 | } 26 | else{ 27 | LR--; 28 | } 29 | } 30 | 31 | return (UD == 0 && LR ==0); 32 | } 33 | } -------------------------------------------------------------------------------- /React Machine Coding/Custom Hook/useIntersectionObserver/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useMemo, useRef, useState } from "react"; 2 | import useIntersectionObsever from "./hooks/useIntersectionObserver"; 3 | import "./styles.css"; 4 | 5 | export default function App() { 6 | const ref = useRef(null); 7 | 8 | const options = useMemo( 9 | () => ({ 10 | root: null, 11 | rootMargin: "0px", 12 | threshold: 0.5, 13 | }), 14 | [] 15 | ); 16 | 17 | const intersectionEntry = useIntersectionObsever(ref, options); 18 | 19 | console.log(intersectionEntry?.isIntersecting); 20 | console.log(intersectionEntry?.intersectionRatio); 21 | 22 | return ( 23 |
      24 |

      Hello

      25 |
      26 |
      33 |

      Subham

      34 |
      35 |
      36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /BigFrontEnd/JS Interview Concept Snippets/PromiseAllSettledPolyfill.js: -------------------------------------------------------------------------------- 1 | function promiseAllSettled(promiseTask) { 2 | let res = new Array(promiseTask.length); 3 | let completed = 0; 4 | 5 | return new Promise((resolve) => { 6 | for (let i = 0; i < promiseTask.length; i++) { 7 | Promise.resolve(promiseTask[i]) 8 | .then((data) => { 9 | res[i] = { status: "fulfilled", data }; 10 | }) 11 | .catch((error) => { 12 | res[i] = { status: "rejected", error }; 13 | }) 14 | .finally(() => { 15 | completed++; 16 | 17 | if (completed === promiseTask.length) { 18 | resolve(res); 19 | } 20 | }); 21 | } 22 | }); 23 | } 24 | 25 | const promise1 = Promise.resolve(1); 26 | const promise2 = Promise.reject(2); 27 | const promise3 = new Promise((resolve) => { 28 | setTimeout(() => { 29 | resolve(30); 30 | }, 1000); 31 | }); 32 | 33 | promiseAllSettled([promise1, promise2, promise3]) 34 | .then((res) => { 35 | console.log(res); 36 | }) 37 | .catch((error) => console.log("One of the promise failed", error)); 38 | -------------------------------------------------------------------------------- /React Machine Coding/BreadCrumb Menu/pages/home.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import { Link } from "react-router-dom"; 3 | 4 | export default function Home() { 5 | const [trendingProducts, setTrendingProducts] = useState([]); 6 | 7 | useEffect(() => { 8 | fetch("https://dummyjson.com/products") 9 | .then((res) => res.json()) 10 | .then((data) => { 11 | const sliceTrending = data.products.slice(0, 6); 12 | setTrendingProducts(sliceTrending); 13 | }); 14 | }, []); 15 | 16 | return ( 17 |
      18 |
      19 | {trendingProducts.map((prod) => ( 20 |
      21 | 22 | 23 |

      {prod.title}

      24 | 25 |
      26 | ))} 27 |
      28 | 29 | 30 | 33 | 34 |
      35 | ); 36 | } 37 | -------------------------------------------------------------------------------- /Geeks For Geeks/DSA 450/007-Kadane_Algorithm.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | Refresh 43 | 44 | Time (IST) Status Lang Test Cases Code 45 | 2022-12-29 21:58:12 Correct java 10133 / 10133 View 46 | class Solution{ 47 | 48 | // arr: input array 49 | // n: size of array 50 | //Function to find the sum of contiguous subarray with maximum sum. 51 | long maxSubarraySum(int arr[], int n){ 52 | 53 | // Your code here 54 | int max_so_far = Integer.MIN_VALUE, max_ending_here = 0; 55 | 56 | for (int i = 0; i < n; i++) { 57 | max_ending_here = max_ending_here + arr[i]; 58 | if (max_so_far < max_ending_here) 59 | max_so_far = max_ending_here; 60 | 61 | if (max_ending_here < 0) 62 | max_ending_here = 0; 63 | } 64 | return max_so_far; 65 | 66 | } 67 | 68 | } -------------------------------------------------------------------------------- /LeetCode/013-3Sum.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List> threeSum(int[] num) { 3 | 4 | Arrays.sort(num); 5 | 6 | List> res = new LinkedList<>(); 7 | 8 | for(int i = 0; i < num.length-2; i++){ 9 | 10 | if(i == 0 || ( i > 0 && num[i] != num[i-1])){ 11 | int lo = i + 1, hi = num.length - 1, sum = 0 - num[i]; 12 | 13 | while(lo < hi){ 14 | if(num[lo] + num[hi] == sum){ 15 | 16 | res.add(Arrays.asList(num[i], num[lo], num[hi])); 17 | 18 | while(lo < hi && num[lo] == num[lo + 1]) lo++; 19 | while(lo < hi && num[hi] == num[hi - 1]) hi--; 20 | 21 | lo++; hi--; 22 | } 23 | else if(num[lo] + num[hi] < sum) lo++; 24 | 25 | else hi--; 26 | } 27 | } 28 | } 29 | 30 | return res; 31 | } 32 | } -------------------------------------------------------------------------------- /Daily Bytes/010-Replace_0_with_5.java: -------------------------------------------------------------------------------- 1 | public class Replace0With5{ 2 | 3 | static int replace0with5(int number) 4 | { 5 | return number += calculateAddedValue(number); 6 | } 7 | 8 | // returns the number to be added to the 9 | // input to replace all zeroes with five 10 | private static int calculateAddedValue(int number) 11 | { 12 | 13 | // amount to be added 14 | int result = 0; 15 | 16 | // unit decimal place 17 | int decimalPlace = 1; 18 | 19 | if (number == 0) { 20 | result += (5 * decimalPlace); 21 | } 22 | 23 | while (number > 0) { 24 | if (number % 10 == 0) 25 | // a number divisible by 10, then 26 | // this is a zero occurrence in the input 27 | result += (5 * decimalPlace); 28 | 29 | // move one decimal place 30 | number /= 10; 31 | decimalPlace *= 10; 32 | } 33 | return result; 34 | } 35 | 36 | public static void main(String []args){ 37 | System.out.print(replace0with5(1020)); 38 | } 39 | } -------------------------------------------------------------------------------- /React Machine Coding/Product_Cart_Publicis_Sapient/components/organisms/CartList.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import ProductCard from "../molecules/ProductCard"; 3 | import { fetchCart, fetchProduct } from "../../services/api"; 4 | 5 | const CartList = () => { 6 | const [cartProducts, setCartProducts] = useState([]); 7 | 8 | useEffect(() => { 9 | const loadCart = async () => { 10 | const cart = await fetchCart(); 11 | const productPromises = cart.products.map((p) => 12 | fetchProduct(p.productId) 13 | ); 14 | const products = await Promise.all(productPromises); 15 | setCartProducts(products); 16 | }; 17 | 18 | loadCart(); 19 | }, []); 20 | 21 | const handleRemove = (productId) => { 22 | setCartProducts(cartProducts.filter((p) => p.id !== productId)); 23 | }; 24 | 25 | return ( 26 |
      27 | {cartProducts.map((product) => ( 28 | 33 | ))} 34 |
      35 | ); 36 | }; 37 | 38 | export default CartList; 39 | -------------------------------------------------------------------------------- /Geeks For Geeks/Arrays/50 Top Problems/001-PeakElement.java: -------------------------------------------------------------------------------- 1 | // GFG Problem Link : https://practice.geeksforgeeks.org/problems/peak-element/1 2 | // GFG Article : https://www.geeksforgeeks.org/find-a-peak-in-a-given-array/ 3 | // Time Complexity : O(Logn) (Divide and Conquer Method) 4 | // YouTube Reference : https://www.youtube.com/watch?v=zNEn4n0IdPY 5 | 6 | 7 | class Solution 8 | { 9 | // Function to find the peak element 10 | // arr[]: input array 11 | // n: size of array a[] 12 | public int peakElement(int[] arr,int n) 13 | { 14 | //add code here. 15 | int low = 0; 16 | int high = n-1; 17 | 18 | while(low <= high){ 19 | 20 | int mid = (high + low)/2; 21 | 22 | 23 | if((mid == 0 || arr[mid - 1] <= arr[mid]) && (mid == n - 1 || arr[mid + 1] <= arr[mid])) 24 | { 25 | return mid; 26 | } 27 | 28 | else if (arr[mid] < arr[mid + 1]){ 29 | low = mid + 1; 30 | } 31 | else { 32 | high = mid - 1; 33 | } 34 | } 35 | return -1; 36 | } 37 | } -------------------------------------------------------------------------------- /CodeForces/B-Social_Network.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | import java.util.Stack; 4 | 5 | 6 | public class HelloWorld{ 7 | 8 | public static void main(String []args){ 9 | 10 | Scanner sc = new Scanner(System.in); 11 | 12 | int n = sc.nextInt(); // The number of friends 13 | int k = sc.nextInt(); // The Size of Conversation displayed on screen 14 | 15 | int no; 16 | Stack phoneC = new Stack<>(); 17 | for(int i = 0 ; i < n ; i++){ 18 | no = sc.nextInt(); 19 | if(!(phoneC.contains(no))){ 20 | if(phoneC.size() == k){ 21 | phoneC.remove(0); 22 | phoneC.add(no); 23 | }else{ 24 | phoneC.add(no); 25 | } 26 | } 27 | else{ 28 | continue; 29 | } 30 | } 31 | 32 | String ans = ""; 33 | System.out.println(phoneC.size()); 34 | 35 | while(!phoneC.isEmpty()){ 36 | ans = ans+phoneC.pop()+" "; 37 | } 38 | System.out.println(ans.trim()); 39 | } 40 | } -------------------------------------------------------------------------------- /HackerRank/JAVA/JavaDatatypes.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | 5 | 6 | class Solution{ 7 | public static void main(String []argh) 8 | { 9 | 10 | 11 | 12 | Scanner sc = new Scanner(System.in); 13 | int t=sc.nextInt(); 14 | 15 | for(int i=0;i= -128 && x <= 127) 23 | System.out.println("* byte"); 24 | if (x >= -(Math.pow(2, 16 - 1)) && x <= (Math.pow(2, 16 - 1) - 1)) 25 | System.out.println("* short"); 26 | if (x >= -(Math.pow(2, 32 - 1)) && x <= (Math.pow(2, 32 - 1) - 1)) 27 | System.out.println("* int"); 28 | if (x >= -(Math.pow(2, 64 - 1)) && x <= (Math.pow(2, 64 - 1) - 1)) 29 | System.out.println("* long"); 30 | } 31 | catch(Exception e) 32 | { 33 | System.out.println(sc.next()+" can't be fitted anywhere."); 34 | } 35 | 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /React Machine Coding/Pagination/Style.css: -------------------------------------------------------------------------------- 1 | .App { 2 | margin: 0px; 3 | border: 0px; 4 | font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; 5 | font-weight: 500; 6 | } 7 | 8 | .products { 9 | margin: 20px; 10 | padding: 0; 11 | list-style-type: none; 12 | display: grid; 13 | gap: 20px; 14 | grid-template-columns: 1fr 1fr 1fr; 15 | } 16 | 17 | .products__single { 18 | width: 300px; 19 | padding: 20px; 20 | text-align: center; 21 | border-radius: 5px; 22 | cursor: pointer; 23 | font-size: 14px; 24 | } 25 | 26 | .prod__image { 27 | width: 100%; 28 | margin-bottom: 5px; 29 | object-fit: cover; 30 | } 31 | 32 | .pagination { 33 | padding: 10px; 34 | margin: 15px 0; 35 | display: flex; 36 | justify-content: center; 37 | } 38 | 39 | .pagination span { 40 | padding: 15px 20px; 41 | border: 1px solid rgb(202, 200, 200); 42 | cursor: pointer; 43 | } 44 | 45 | .selected__page { 46 | background-color: #036dd7; 47 | color: #fff; 48 | border: none; 49 | } 50 | 51 | .pagination__disable { 52 | display: none; 53 | } -------------------------------------------------------------------------------- /BigFrontEnd/DSA /0316_Remove_Duplicate_Letters.js: -------------------------------------------------------------------------------- 1 | var removeDuplicateLetters = function(s) { 2 | const stack = []; 3 | const seen = new Set(); 4 | const lastIndex = {}; 5 | 6 | // Record the last occurrence of each character 7 | for (let i = 0; i < s.length; i++) { 8 | lastIndex[s[i]] = i; 9 | } 10 | 11 | for (let i = 0; i < s.length; i++) { 12 | const char = s[i]; 13 | 14 | // Skip if the character is already in the result 15 | if (seen.has(char)) continue; 16 | 17 | // Remove characters from the stack if: 18 | // 1. They are lexicographically larger than the current character 19 | // 2. They still have occurrences later in the string 20 | while ( 21 | stack.length > 0 && 22 | stack[stack.length - 1] > char && 23 | lastIndex[stack[stack.length - 1]] > i 24 | ) { 25 | seen.delete(stack.pop()); 26 | } 27 | 28 | // Add the current character to the stack and mark it as seen 29 | stack.push(char); 30 | seen.add(char); 31 | } 32 | 33 | // Join the stack to form the final string 34 | return stack.join(''); 35 | }; -------------------------------------------------------------------------------- /React Machine Coding/Star Rating/StarRating.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | const StarRating = ({ size = 5, rating, onChange = () => {} }) => { 4 | const [hoverRating, setHoverRating] = useState(0); 5 | 6 | const handleStarHover = (hoveredRating) => { 7 | setHoverRating(hoveredRating); 8 | }; 9 | return ( 10 |
      11 | {Array(size) 12 | .fill("") 13 | .map((_, i) => { 14 | let starClass = "star"; 15 | const starValue = i + 1; 16 | 17 | if (hoverRating >= starValue) { 18 | starClass += " hover"; 19 | } else if (rating >= starValue) { 20 | starClass += " active"; 21 | } 22 | 23 | return ( 24 | onChange(starValue)} 28 | onMouseEnter={() => handleStarHover(starValue)} 29 | onMouseLeave={() => handleStarHover(0)} 30 | > 31 | ★ 32 | 33 | ); 34 | })} 35 |
      36 | ); 37 | }; 38 | 39 | export default StarRating; 40 | -------------------------------------------------------------------------------- /React Machine Coding/JS Machine Coding/Stop Watch/script.js: -------------------------------------------------------------------------------- 1 | let timer = null; 2 | let elapsedSeconds = 0; 3 | 4 | const display = document.getElementById("display"); 5 | const start = document.getElementById("start"); 6 | const stop = document.getElementById("stop"); 7 | const reset = document.getElementById("reset"); 8 | 9 | function formatTime(seconds) { 10 | const hrs = String(Math.floor(seconds / 3600)).padStart(2, "0"); 11 | const min = String(Math.floor((seconds % 3600) / 60)).padStart(2, "0"); 12 | const secs = String(Math.floor(seconds % 60)).padStart(2, "0"); 13 | 14 | return `${hrs} : ${min} : ${secs}`; 15 | } 16 | 17 | function updateDisplay() { 18 | display.textContent = formatTime(elapsedSeconds); 19 | } 20 | 21 | start.addEventListener("click", function () { 22 | if (timer) return; 23 | timer = setInterval(function () { 24 | elapsedSeconds++; 25 | updateDisplay(); 26 | }, 1000); 27 | }); 28 | 29 | stop.addEventListener("click", function () { 30 | clearInterval(timer); 31 | timer = null; 32 | }); 33 | 34 | reset.addEventListener("click", function () { 35 | clearInterval(timer); 36 | timer = null; 37 | elapsedSeconds = 0; 38 | updateDisplay(); 39 | }); 40 | 41 | updateDisplay; 42 | --------------------------------------------------------------------------------