{{ message }}

Instantly share code, notes, and snippets.

Agnel Waghela agnel

Last active Jun 16, 2022
Codesignal - Aracde Intro - Edge of the Ocean - shapeArea

Codesignal

Aracde > Intro > Edge of the Ocean

Challenge: shapeArea

Created Jun 10, 2022
Algorithm I Day 3 Two Pointers 167. Two Sum II - Input Array is Sorted
View day-3-two-pointers-167-two_sum_ii_input_array_is_sorted.md

Logic: The approach to this question differs to that of the classic Two Sum problem in that we have some direction with how we want to search for our target.

Since the array is sorted, we can make some general observations:

Smaller sums would come from the left half of the array Larger sums would come from the right half of the array Therefore, using two pointers starting at the end points of the array, we can choose to increase or decrease our current sum however we like. Pay attention to the example below:

Created Jun 10, 2022
The SimpleStorage contract in Solidity from Lesson 1: Welcome to Remix! Simple Storage on FreeCodeCamp
View SimpleStorage.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 // SPDX-License-Identifier: MIT pragma solidity >= 0.6.0 <0.9.0; contract SimpleStorage { // this will get initialized as 0 uint256 favoriteNumber; struct People { uint256 favoriteNumber; string name;
Last active Jun 10, 2022
Leetcode 189. Rotate Array
View algorithm-i-day-2-two-pointers-189-rotate-array.md

The official Leetcode page talks about four following approaches:

1. Approach 1: Brute Force
2. Approach 2: Using Extra Array
3. Approach 3: Using Cyclic Replacements
4. Approach 4: Using Reverse

The second approach can be done like this: (but only works in irb and not on leetcode somehow)

Last active Jun 9, 2022
Leetcode 977. Squares of a Sorted Array
View algorithm-i-day-2-two-pointers-977-squares_of_a_sorted_array-explanation.md

The Optimized implementation of Bubble Sort from GeeksforGeeks failed the below test case:

Code:

```# @param {Integer[]} nums
# @return {Integer[]}
def sorted_squares(nums)
nums = nums.map { |n| n*n } # square the numbers

# now lets sort with bubble sort```
Last active Jun 4, 2022
Codility Challange: PrefixSet [Ruby solution]
View prefix_set.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 =begin Codility Challange: PrefixSet https://app.codility.com/programmers/task/prefix_set/ Solution: https://codility.com/media/train/solution-prefix-set.pdf =end def prefixSetGolden(arr) n = arr.size occur = {}
Last active May 17, 2022
Solution to Qiskit Textbook Chapter 2 Exercise 3.4 Question 2
View qiskit-chapter-2-exercise-3.4-question-2.ipynb
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Last active May 17, 2022
Solution to Qiskit Textbook Chapter 2 Exercise 3.4 Question 1
View qiskit-chapter-2-exercise-3.4-question-1.ipynb