fabiochiu/medium-articles huggingface dataset:
Lottery For The Parents And Grandparents Program Might Be Delayed
By: Betterplace Immigration
Tags: Betterplaceimmigration, Family, Canada Immigration, Canada, Immigration

The Parents and Grandparents Program or PGP 2020 is a popular option, especially since family reunification is one of the Canadian immigration goals. Now that the expression of interest window has closed, it is time for IRCC to hold the lottery.

However, as things stand, it seems that the IRCC will delay the immigration lottery till next year. Applicants will have to wait until early 2021 to get their results. Canada planned to hold the lottery by the end of December, but the pandemic is still posing problems.

The Expression of Interest window for the PGP this year opened between October 13 and November 3. Potential sponsors were able to submit their applications during this period. Permanent residents and Canadian citizens had to submit their form online to IRCC to make their wish of sponsoring their parents and grandparents known. IRCC was going to select eligible sponsors through a randomized lottery.

Canadian PR Visa From The Comfort of Your Home! Discover Your Immigration Options Today!

IRCC’s Response

According to the IRCC website, the sponsors are going to receive invitations to apply towards the end of 2021. The applications need to be submitted by early 2021. IRCC offered an explanation for the delay in an email to CIC News.

IRCC is in the process of going through the submissions made this year. The goal is to eliminate duplicates and create a new, randomized list. As soon as the list is prepared, IRCC will send out invitations to apply. The pandemic caused the program to open late this year, and there are other problems that are still holding back progress.

The PGP is a helpful pathway for immigrants who want to bring their parents and grandparents into Canada by sponsoring them.

Canadian PR Visa From The Comfort of Your Home! Discover Your Immigration Options Today!
Manitoba’s Largest Draw Of 2020 On December 17
By: Betterplace Immigration
Tags: Immigration, Betterplaceimmigration, Canada Immigration, Canada, Manitoba

2020 is ending, and Canadian immigration is working twice as hard since the year has presented so many difficulties for candidates.

Manitoba, however, is completing 2020 on a positive note. The province recently held the largest draw of the entire year on December 17. The Manitoba Provincial Nominee Program issued invitations to 419 candidates who will now be allowed to submit an application for a provincial nomination. International graduates and skilled workers received invitations during the draw do they can apply to any of the following streams:

Skilled Workers in Manitoba

International Education Stream

Skilled Workers Overseas

Requirements of the draw

Each category required candidates to have a minimum Expression of Interest score. Candidates in the Skilled Workers in Manitoba needed a minimum score of 375, and they managed to secure 329 LAAs.

The Skilled Workers Overseas stream required candidates to have a score of at least 707 and they got 50 LAAs in total. On the other hand, the applicants under the International Education Stream had no EOI score requirement, and they received 40 LAAs.

With this draw, the number of LAAs distributed so far in 2020 has risen to 4,888. The Manitoba Provincial Nominee Program included candidates from the Skilled Worker Overseas stream in this draw if they got invitations via the strategic recruitment program.

Candidates engaged in a regulated occupation got invited during this draw. According to the MPNP, they have the right to reject candidates who are not occupied in a regulated profession. 37 of the 419 LAAs distributed were given to Express Entry candidates. They are required to have a job seeker validation code, a valid Express Entry ID, and experience in any of the province’s In-demand Occupations list.

Canadian PR Visa From The Comfort of Your Home! Discover Your Immigration Options Today!
Still Standing Unattached at the Top of the Empty Safety Net Valleys
By: Francine Fallara
Tags: Life Lessons, Immigrants, Life, Immigration, Poetry

Migratory currents towards distant horizons, drastic separation from the cozy plump family nest, deep scars oscillating between the uncertainty of regrets of isolation, and the dazzling panorama of inaccessible dreams.

Determined steep slopes ascension, stages of trials through spirited rocky avalanches obstacles, ongoing free falls, surmounting the peak of our inner strength without safety nets, nostalgic pauses sparkling our origins.
I WAS BORN OF THIS
Tags: Mental Illness, Cbc, Immigration

I am constantly battling with severe mental illness. I call it a 3 piece trilogy. #1 Before seeking help, #2 trial and error with meds, and #3 End result.
[Leet Code] Range Sum of BST
By: Matthew Boyd
Tags: Leetcode, Data Structures, Leetcode Solution, Algorithms, Leetcode Easy

Leetcode: https://leetcode.com/problems/range-sum-of-bst/

Given the root node of a binary search tree, return the sum of values of all nodes with a value in the range [low, high] .

Example 1:

Input: root = [10,5,15,3,7,null,18], low = 7, high = 15

Output: 32

Example 2:

Input: root = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10

Output: 23

Constraints:

The number of nodes in the tree is in the range [1, 2 * 104] .

. 1 <= Node.val <= 105

1 <= low <= high <= 105

All Node.val are unique.

Solution:
Binary Trees and Javascript
By: Gary Cordero Rosa
Tags: JavaScript, Computer Science, Data Structures, Algorithms

A tree is a hierarchical data structure composed of nodes. At the top of this data structure, is the root node pointing to a subtree of children. A good example of a tree data structure is the file system used by our OS.

File System

A binary tree is the kind of tree where each node has at most two children. A binary tree node is composed of a value and two pointers (usually refer as left and right pointers).

Binary Tree

Implementing a Binary Tree in Javascript

To implement a binary tree in javascript we would need to create two classes, the Node Class and the BinaryTree Class.

As discuss before each node has a value and two pointers.

Now we can implement our binary tree in the following way.

Once we implement these classes we can use our binary three, by passing a root node to our BinaryTree constructor and assigning the child nodes as needed.

If we log our root node we can see how the tree structure is being created
Fenwick Tree (Binary Indexed Tree)
By: Aman Bharti
Tags: Computer Science, Data Structures, Programming Languages, Programming, Algorithms

Fenwick tree, also known as Binary Indexed Tree is data structure which is commonly used for range problems like getting sum of a range and updating a element of array. we can also use prefix sum for getting sum of range but updating array in prefixsum approach takes O(n).

=> It calculates sum of all elements of a range [l , r] of array in O(log n) time.

=>It update the value of any element of array on O(log n) time.

=>It taken only O(n) memory space to do these operations.

Fenwick Tree ,Which i am going to discuss here is zero based indexing. we can also do one based indexing.

Image taken from EMAXX

In this each node cover some region so when we update an element than we have to update only those nodes which covers region contaning that element. For ex in above figure if we have to update 3rd element than we will update node 2 ,3 and 7 only.

As fenwick tree is represented as array so how to reach parent node?

let us take current node as i than We can go to parent node as i|(i+1)

for ex:

2|(2+1) = 3

3|(3+1) = 7 and so on.

node (size of array -1) will be parent of all nodes as 7 is parent for all nodes for array of size 8

so we can update parent node by using loop from the position where we want to update to all its parent nodes.

Now How to get sum of a range(l,r) from array?

sum = prefixsum(r)-prefixsum(l-1)

if some how we get sum of all parent nodes from r to 0 than we can get sum of range using above formula.

for ex :

if from above figure we want sum of elements from index 0 to 5 than we do no require to go every nodes from 0 to 5. we can say sum as node 3 +node 5 as node 3 is parent of node 0,1and 2. so node 3 will contain sum of node { 0,1and 2}. so how to go from node 5 to node 3.

next_node = (i&(i+1))-1 assuming i as current node

for ex : (5&(5+1))-1 = 3

(6&(6+1))-1 = 5

thus by traversing (using loop) from current node to node greater than or equal to 0 we can get sum of prefix(r)

sum of range(l,r) = prefix(r)-prefix(l-1)

Initially we take all elements of fenwick tree as 0 and add all elements by using update function.
5 Steps to improve your Programming Skills
Tags: Data Structures, Technology, Programming, Algorithms, Coding

Programming Languages

To improve your programming skills the first thing we need to understand a Basic Syntax of every Language. Every programming language like C, C++, Java, Python, PHP, Perl, Ruby, etc. Have there own Syntax please make sure foundation should be always strong.

Once you know the Syntax please use following steps mentioned.
Stacks & Queues — Data Structures
By: Ronan Mcclorey
Tags: Stacks, Queues, Data Structures, Computer Science

Data structures are a big part of computer science and programming and are frequently used in programming. I will go into more detail about two data structures that are often grouped together in learning Stacks and Queues.

Stacks

Photo by Madalyn Cox on Unsplash

One of the main properties of a stack is LIFO which stands for Last In First Out. If we think of a ‘stack’ of books like in the above picture the last one put on is at the top and it would be the first one you would take off. So when removing from a stack we can only remove the last item inserted. The main functions we associate with stacks is insertion and removal (adding to the top of the stack and removing from the top of the stack). Both of these in terms of Big O have a constant runtime (O(1)). It is possible to simply use an array and make it behave like a stack by only using the built-in array methods push and pop.

Queues

Photo by Melanie Pongratz on Unsplash

A queue in a way is almost the opposite of a stack in that its main property is FIFO which is First In First Out. Again looking at the above picture when you ‘queue’ up to get in somewhere the first person in line is the first person to get in or off the line. Similarly to stacks, the functions of a queue are mainly insertion and removal (enqueue and dequeue) and like stacks have Constant runtime. We can’t make an array behave like a queue however because we would have to use either shift or unshift and that wouldn't give us constant time. For a queue, we would have to build out the data structure.

More on both

Stacks and queues aren’t very complex data structures as you can see they are restricted by rules for adding to and removing from them. They work very efficiently in this though with constant runtime. Therefore are useful if you need a data structure that is good in that aspect and follows the FIFO or LIFO order. Searching or gaining access to a particular node is O(n) because there's no order or simpler way of doing this. Furthermore, just simply based on the rules we can’t insert a node at just any point for queues nodes always goto the end and for stacks nodes always go to the top. Likewise for removing nodes.
A visual guide to 0–1 BFS
By: Abhimanyu Shekhawat
Tags: Computer Science, Graph Theory, Data Structures, Programming, Algorithms

Novel problems require tailored solutions. Sometimes, taking a detour and a fresh look at the problem can significantly reduce its complexity. Today we’ll talk about one such technique called 0–1 Breadth First Search.

Welcome! To the brand new article of Code Stories where we solve interesting problems using the fundamentals of Computer Science. 🚀

Just like our last post regarding Dynamic Programming, we’ll first understand the problem statement. After that, we’ll start exploring solution approaches and gradually develop the intuition for 0–1 BFS. Following that, we will code the entire solution. 🎉

This article assumes that you have a basic understanding of graphs and how they are traversed.

The Problem ❓

Captain Dlon Husk has finally embarked on an adventure to discover new worlds beyond his own. He is using the latest SpaceY Shuttle for this adventure. 🚀

After a few wormhole jumps he enters into a Space-Time Matrix of NxM dimensions (1 ≤ N, M ≤ 2000) . Since it’s a 2-D matrix his Shuttle too can just move in 4 directions Top, Bottom, Left and Right.

He finds out that this part of the universe is pretty strange, as certain cells of the Matrix have the influence of Dormammu, the destroyer of the worlds. Landing on one of these would mean instant death. Luckily he is currently on a Martian cell [R,C] . Dlon likes Martian cells as they give him faith.

But this is not all, he discovers that the space-time jumps have damaged the thrusters which move the Shuttle Left and Right. So now he can only move Left and Right X and Y times respectively (0 ≤ X, Y≤ 10⁹) . Note that there are NO restrictions on the Up and Down movement.

Dlon is already missing his son (The one named after a coupon code) and wants to return home. But he needs faith for the journey back home. Your task is to help Dlon determine the number of Martian cells within his reach.

The Strategy 💡

Since this problem involves a lot of visualization, let’s look at the following illustration to understand it better.
Minumum Cost to Move Chips to the Same Position — LeetCode
By: Soren Rood
Tags: Computer Science, Computer Science Student, Leetcode, Data Structures, Algorithms

Here is the problem:

LeetCode #1217

This problem stumped me at first. I first thought that each index was a token holder and the number represented the number of tokens at that index. I was trying to solve this way for a long time. Eventually, I started reading the discussion section of the problem and figured it out.

Here is my code that solves the problem:

https://carbon.now.sh

The most important thing to realize for this problem is that it’s free (no cost) to move a chip from an odd index to another odd index. You only have to increment the cost when you move a chip from an odd index to an even index, and vice versa.

With that in mind, we can iterate through all of the chips, and check if it’s even or odd. If it’s even, we do even_parity += 1, and if it’s odd, we do odd_parity += 1. After we have those numbers, we want to return the smallest number.

“All chips must be in the same position once we’re done, which is either even or odd. Therefore, we want to calculate whether it is cheaper to move all the odd chips to even or all the even chips to odd. This will simply come down to how many even chips we start with, and how many odd chips. Each chip that has to be moved will cost exactly 1” (Explanation referenced from here).

Here’s the submission report for the above code:
Help Santa — Detailed Solution. In this blog, we are going to look at…
By: Ainesh Phanithi
Tags: Data Structures, Algorithms, Problem Solving, Coding

In this blog, we are going to look at the problem “Help Santa” from the contest “Numbers Quest” organized by The Coding Culture on 23rd December, 2020.

Problem:

Santa is preparing gifts for the children who were good this year. He decided to give more than 1 gift to children who were really well behaved, and so labelled gift boxes with the same number of the child that was on his list. But in the end, he realized that he did not have enough gifts to put into gift boxes so he removed duplicate gift boxes. Print the gift boxes without any repetition.

Input:

First line will contain N number of elements in the array

The next line contains the elements in the array, entered with a space between each element.

Output:

For each testcase, output the answer you get in a sequential manner with a space in between each element.

Constraints: 1 <= n <= 10⁶ 1 < = A[i] <= 30

Sample Input:

12

2 3 7 5 5 2 8 1 4 6 6 6

Sample Output:

1 2 3 4 5 6 7 8

Constraints:

1 <= n <= 10⁶

1 < = A[i] <= 30

Analysis:

Approach:

There are many ways we can solve this problem. I will be discussing 3 ways to do so.

Brute Force Approach: Take a for loop and insert an element that you have traversed into a list(vector in c++) only if the element is not present in the list beforehand. Using a Set Data Structure: Insert all the elements of the array into a Hash Set. As a Set only stores unique values, you can directly print the values in the set. Optimal solution: Find the maximum element in the input array, and then run a for loop and print the elements from i=1 to maxElement.

The solutions for these 3 methods are given below, with their corresponding time complexities.

Brute Force Approach:

Time Complexity: O(N²)

Solution using C++:

2. Using a Set Data Structure:

Time Complexity: O(Nlog(N))

Solution using C++:

This solution, as you can see, is very straightforward. As a set stores only unique elements, we can use this property and convert the array which was given as input into a set.

3. Optimal Solution:

Identify the largest number in the array and use a for loop to print the values from 1 to the largest number you identified.

Time Complexity: O(N)

I have used the same name of the function for the 3 different approaches to focus on the point that the purpose of the 3 functions are the same, just the implementation varies. The most optimal approach is the third solution as it executes in a linear time.
Call Me By My Name…. Recursion
By: David Kirsch
Tags: Math, Recursion, Data Structures, Programming, Algorithms

If you are new to programming, or even if you aren't, you have probably heard of a type of algorithm called Recursion and freaked out. This is normal and with time you will soon realize that the name may sound daunting, but it is really quite simple.

Russian Dolls

The simplest way to think of recursion is by using an analogy like a Russian Doll set. In order to get the the smallest doll, you have to continue to go into itself and see if there is anything else within it. Finally, when you get to the inner most doll, you can take it out and place all the other ones back in, one by one.

How does that analogy fit in with programming?

Well, let’s look at an example of how recursion would be used to solve a problem.

Puppies always make things better….here’s an infinite amount!

Recursion has 2 parts to the algorithm, a recursive call and a base case. The recursive call is the function that is going to be repeatedly called within itself, while the base case is the stopping point at which you want your function to stop calling itself. IMPORTANT: Make sure you have a base case. Without it, your program will crash due to an infinite loop.

So let’s use a math function like factorials. If you are a little rusty in math, that is fine, we will briefly go over factorials to refresh your memory. Factorials are the product of all the positive integers from 1 to n. Factorials are denoted by the given integer along with an exclamation point (i.e. 5!). So 5! would be 5 * 4 * 3 * 2 * 1, which equals 120.

Ok, now that we quickly refreshed ourselves, let’s dive into the example.

Recursive example

Let’s break this function down to understand what is going on. We have a function called factorial, which accepts a number, n. While n is greater than 0, the function will call itself, subtracting 1 from the current value of n each time till it equals 0.

The above screenshot shows how the function works each time it dives deeper into itself. Let’s start at line 16. We make a call to the function called factorial with the number 5 as the argument. Since 5 is not equal to 0 (line 4), it skips that command and calls itself (line 8), except now subtracting 1 from 5. You can also see the function being returned is also being multiplied by n.

When we finally hit 0, we return 1 (line 5). Now is where all the math begins. The function has went 5 levels within itself before hitting 0 and now works its way back up.

Starting at line 18, we see that 1 is multiplied by the function factorial(0) which is 1, then it moves up to line 16. Factorial(1) now is multiplied by 2, which return 2. It does this all the way back up till we get to our top level which was when n === 5. The returned result would be 120.

Hopefully this helped clear up any confusion you had about Recursion. The best way to learn is by doing. So try solving some problems using recursion and over time you will get the hang of it!
[Leet Code] Generate a string with characters that have odd counts
By: Matthew Boyd
Tags: Leetcode, Data Structures, Leetcode Solution, Algorithms, Leetcode Easy

Leetcode: https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts/

Problem:

Given an integer n , return a string with n characters such that each character in such string occurs an odd number of times.

The returned string must contain only lowercase English letters. If there are multiples valid strings, return any of them.

Example 1:

Input: n = 4

Output: "pppz"

Explanation: "pppz" is a valid string since the character 'p' occurs three times and the character 'z' occurs once. Note that there are many other valid strings such as "ohhh" and "love".

Example 2:

Input: n = 2

Output: "xy"

Explanation: "xy" is a valid string since the characters 'x' and 'y' occur once. Note that there are many other valid strings such as "ag" and "ur".

Example 3:

Input: n = 7

Output: "holasss"

Solution:
[Leet Code] Unique Morse Code Words
By: Matthew Boyd
Tags: Leetcode, Data Structures, Leetcode Solution, Algorithms, Leetcode Easy

Leetcode: https://leetcode.com/problems/unique-morse-code-words/

International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-" , "b" maps to "-..." , "c" maps to "-.-." , and so on.

For convenience, the full table for the 26 letters of the English alphabet is given below:

[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]

Now, given a list of words, each word can be written as a concatenation of the Morse code of each letter. For example, “cab” can be written as “-.-.. — …”, (which is the concatenation “-.-.” + “.-” + “ -... "). We'll call such a concatenation, the transformation of a word.

Return the number of different transformations among all words we have.

Example:

Input: words = ["gin", "zen", "gig", "msg"]

Output: 2

Explanation:

The transformation of each word is:

"gin" -> "--...-."

"zen" -> "--...-."

"gig" -> "--...--."

"msg" -> "--...--." There are 2 different transformations, "--...-." and "--...--.".

Note:

The length of words will be at most 100 .

will be at most . Each words[i] will have length in range [1, 12] .

will have length in range . words[i] will only consist of lowercase letters.

Solution:
Longest Common Prefix
By: Rishikesh Dhokare
Tags: Leetcode, Data Structures, Leetcode Solution, Programming, Algorithms

Hope this helps! Happy coding! 🙂

If you think the solution can be improved or misses something, feel free to comment. There is always some room for improvement.

Find the solutions to the leetcode problems here — https://github.com/rishikeshdhokare/leetcode-problems
3: Longest Substring without Repeating Characters
By: Seunghyeon Shin
Tags: Computer Science, Leetcode, Coding Interview, Algorithm, Data Structure

Handling the Exception

For most of the algorithm problems, there are always the static component that does not require us to develop more complex solutions.

In this case, we should note that the solution always equals to the length of given input if the length of input is 0 or 1 as null input or one-length input can only have one substring that is valid. That being said, we can make an exceptional statement:

if (s.length() <= 1) {

return s.length();

}

Declaration of Variables and Data Structure

While I need a variable ‘max’, which reflects the count of the repeated data, I also need the container to store data to solve this problem, and I want to use ArrayList for this case.

int max = 0; // (1)

List <Character> list; // (2)

In this situation, I focus on solving the problem rather than maximizing the time and space complexity. The point of this stage is to show you know how to improve the efficiency of code.

for (int i = 0; i < s.length() - 1; ++i) { // first 'for' loop

list = new ArrayList<>();

list.add(s.charAt(i));for (int j = i + 1; j < s.length(); ++j) { // nested 'for' loop

if (list.contains(s.charAt(j))) {

if (max < list.size()) {

max = list.size();

}

break;

} else {

list.add(s.charAt(j));

}

}

}

At the first-level loop, I launch the process to begin each iteration beginning with the specific character.

for (int i = 0; i < s.length() - 1; ++i) { // first 'for' loop

list = new ArrayList<>();

list.add(s.charAt(i));

Why the iteration range is only up to s.length()-1? It is because the reason of this iteration is to compare the previous character and its immediately-next one. Because the iteration is pair-based, we need to go only up to the second from the last character. That is how we can secure the last one to compare in the last case.

At the second-level loop, we begin with the second from the first-character, having a second character to compare with the ones stored in the list.

Now, we use the conditional statement:

for (int j = i + 1; j < s.length(); ++j) { // nested 'for' loop

if (list.contains(s.charAt(j))) {

if (max < list.size()) {

max = list.size();

}

break;

}



else {

list.add(s.charAt(j));

}

}

If the list already contains the character indicated in the second loop, we just end the loop process because the aim for this code is to find out “Longest Substring Without the Repeating Characters”.

If the loop ends here, we need to check if the substring is longer than the previously-maximum one. If it is the longest, we need to update the max variable:

if (list.contains(s.charAt(j))) {

if (max < list.size()) {

max = list.size();

}

break;

}

But what if the iteration loop ends as the loop ended? In this case, we skip the process to update the maximum value. For this case, we add the code outside of the first loop:

max = (list != null && list.size() > max) ? list.size() : max

The process ends if we just return the max variable.
本篇主要針對不同類型的 Binary Tree 做簡介, 專有名詞部分依照英文呈現不另外做翻譯, 如果對一些特別的 term 不熟悉的, 可以參考 Tree 的簡介 每一個 node 都有 0 個或 2 個 child node, 也就是說要嘛就不要有 child node, 要嘛就是 2 個, 沒有那種 1 個的。 又稱為 proper tree 或 plane binary tree…
By: Ray Lee
Tags: Trees, Data Structures

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
Valid Parentheses | Leetcode #20 | Easy
By: Rishikesh Dhokare
Tags: Leetcode, Data Structures, Leetcode Solution, Programming, Algorithms

Solution:

As mentioned in the problem statement, parentheses, braces and brackets (I will just call them brackets in the text below) should be closed by the same type. i.e '(' needs to be closed by ')' . This seems to be a pair of characters that work together. Let’s use this concept to build the algorithm to solve this problem.

Create a map called charMap which stores the opening and it’s corresponding closing character. The best suitable data structure for this use case is Stack because of it’s Last-In-First-Out(LIFO) nature i.e. last inserted element will be taken out first. So, let’s create a variable stack of type Character. For each character in the input string follow the steps from #4 to #6 If the charMap contains a key with the character, that means it is one of the opening brackets and hence we push it to the stack . Else, it is one of the closing brackets. Now, (a) get the top element from the stack using pop() method (b) get the value for that element from the charMap (c) compare it with the current character in the iteration. If they don’t match, it means they are not the matching brackets and hence we return false. There is another corner case where the closing bracket is the last character in the string after all the matching brackets or closing bracket is the only character in the input string. In this case we need to add another or condition to the if block in step #5 to check is stack is empty. In the end if the stack is empty, we have all the brackets matching and hence we return true. Otherwise return false.

This is how the code looks like —
Intersection Point in Y Shaped Linked Lists
By: Kriti Mittal
Tags: Data Structures, Singly Linked List, Java, Programming, Linked Lists

Link:-

Description :-

Given two singly linked lists of size N and M, write a program to get the point where two linked lists intersect each other.

Example 1:

Input:

LinkList1 = 3->6->9->common

LinkList2 = 10->common

common = 15->30->NULL

Output: 15

The task is to complete the function which takes the pointer to the head of linklist1(head1) and linklist2(head2) as input parameters and returns data value of a node where two linked lists intersect. If linked list do not merge at any point, then it should return -1.

Expected Time Complexity: O(N+M)

Expected Auxiliary Space: O(1)

Constraints:

1 <= N <= 100

1 <= value <= 1000

Solution:-

Step 1: Maintain a pointer which points to head of linkedlist1 and b pointer which points to head of linkedlist2. Step 2 : If a pointer is null them set point a pointer to head of linkedlist2.If not, then move a pointer to next node. Step 3 : If b pointer is null them set point a pointer to head of linkedlist1.If not, then move b pointer to next node. Step 4: Continue step 2 and step 3 until a pointer is not equal to b pointer. Finally, return the value of data contained in node pointed by either a pointer or b pointer.

Below is the java solution for this problem:
Visualizing, Designing, and Analyzing the Bubble Sort Algorithm.
By: Vikram Gupta
Tags: Sorting, Data Structures, Bubble Sort, Sorting Algorithms, Programming

Now Let’s Design the Bubble Sort Algorithm :

Below is working code for what we visualized in the above example.

Bubble sort algorithm

OUTPUT:

Array elements before sorting:

9 7 5 3 1

Array elements after sorting:

1 3 5 7 9

Time and Space Complexity Analysis:

Time Complexities:

Best Case:

In the above implementation, even if the input array is already sorted in the ascending order, for each pass the inner ‘for’ loop will execute. And hence making its best and worst time complexities same which can be calculated as follows:

no of times inner ‘for’ loop executes for n number of elements in the array:

(n-1) + (n-2) + (n-3) +… + 3 + 2 + 1 = n(n-1)/2

Hence for Bubble sort best case time complexity is O(n2).

Worst Case:

The worst case occurs when the array elements are reversed sorted. In this case also the above equation holds. And hence making its best and worst time complexities the same, that is O(n2).

Optimized Bubble Sort :

We can add a boolean variable to check if swapping of numbers(elements) actually occurs or not in the inner ‘for’ loop. For one of the passes if this variable remains false then we can say that the array is sorted one and break the outer ‘for’ loop. See the below program for modifed/optimized bubble sort algorithm.

The optimized bubble sort algorithm

Best Case of Optimized Bubble sort:

As we have added a boolean check to break the outer ‘for’ loop when no swap occurs in one of the passes. So in the case, when the array elements are already sorted in ascending order, in the first pass only the outer ‘for’ loop will break. So the time complexities will be linear (O(n)).

Worst Case of Optimized Bubble sort:

The worst case occurs when the array elements are reversed sorted. In this case: no of times inner ‘for’ loop executes for n number of elements:

(n-1) + (n-2) + (n-3) +… + 3 + 2 + 1 = n(n-1)/2

So the worst case time complexity will be O(n2).

2. Space Complexity: O(1).
Visualizing, Designing, and Analyzing the Selection Sort Algorithm.
By: Vikram Gupta
Tags: Data Structures, Sorting Algorithms, Software Engineering, Selection Sort, Programming

Is Selection Sort stable?

Definition of stable : the relative order of elements with the same value is maintained.

Selection sort is not a stable algorithm.

Basically in selection sort , swap that occurs at the end of each iteration can change the relative order of items having the same value.

For example, let’s assume you have array elements as 4 2 3 4 1 with selection sort .

The first iteration will go through each element looking for the minimum element. It will find that 1 is the minimum element. And then it will swap the 1 into the first spot that is 4. This will cause the 4 in the first spot to go into the last spot: 1 2 3 4 4

Now the relative order of the 4’s has changed. The ‘first’ 4 in the original list has been moved to a spot after the other 4.

Hence the Selection sort algorithm is not stable.

Is Selection Sort In-place?

It does not use any extra space for sorting the array elements hence it is an In-place sorting algorithm.
Happy Number Solution Leetcode
By: Tochukwu Munonye
Tags: Data Structures, Java, Hackathons, Software Development, Algorithms

Problem

Write an algorithm to determine if a number n is "happy".

First of all you have to understand what a happy number is. A happy number is a number that when you keep adding the squares of each of its digits, it will end up as 1.

Let’s take the number 19 for example

If you square each digit 1 and 9 and add them you will get 82. Repeat the process for 82 and you will get 68. If the loop continues it will end at 1 which makes 19 a happy number. Cool right?

So the big question is how can we solve this problem with code?

Here’s the answer and the steps explained below;

First we check for edge cases, we start by saying if n is equal to 1 it’s definitely a happy number so we would return true.

We initialize a HashSet. A HashSet is a data structure that only contains unique values. Then we add the number into the hashset.

We create a variable called result. Result at first will be zero but later it will be set to the sum of the squares of each digit.

We create a helper function called ↓getResult↓ . This will take in any number. While the number is not zero, to get the sum of squares of each digit you create another variable called ↓result↓. Then for the first digit you first find the mod 10 of the number. The mod 10 will give you the remainder of the number divided by 10. For example the number “19" mod 10 will give you 9, you times it by its self. Then to get the second digit you divide number by 10 which will give you one. You get the mod 10 of 1 and times by itself.

You check if the HashSet contains the result (sum of squares of each digit), if it does it is not a happy number.

If it doesn’t you will keep adding the result to the HashSet and set the result as the number.

If the loop doesn’t break it will end up as 1, which makes it a happy number.

Happy Coding guys! Do follow me on twitter from my profile, thanks.
[Leet Code] Consecutive Characters
By: Matthew Boyd
Tags: Leetcode, Data Structures, Leetcode Solution, Algorithms, Leetcode Easy

Leetcode: https://leetcode.com/problems/consecutive-characters/

Problem:

Given a string s , the power of the string is the maximum length of a non-empty substring that contains only one unique character.

Return the power of the string.

Example 1:

Input: s = "leetcode"

Output: 2

Explanation: The substring "ee" is of length 2 with the character 'e' only.

Example 2:

Input: s = "abbcccddddeeeeedcba"

Output: 5

Explanation: The substring "eeeee" is of length 5 with the character 'e' only.

Example 3:

Input: s = "triplepillooooow"

Output: 5

Example 4:

Input: s = "hooraaaaaaaaaaay"

Output: 11

Example 5:

Input: s = "tourist"

Output: 1

Constraints:

1 <= s.length <= 500

s contains only lowercase English letters.

Solution:
Roman to Integer | Leetcode #13 | Easy
By: Rishikesh Dhokare
Tags: Leetcode, Data Structures, Leetcode Solution, Programming, Algorithms

Problem:

Roman numerals are represented by seven different symbols: I , V , X , L , C , D and M .

Symbol Value

I 1

V 5

X 10

L 50

C 100

D 500

M 1000

For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII , which is simply X + II . The number 27 is written as XXVII , which is XX + V + II .

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII . Instead, the number four is written as IV . Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX . There are six instances where subtraction is used:

I can be placed before V (5) and X (10) to make 4 and 9.

can be placed before (5) and (10) to make 4 and 9. X can be placed before L (50) and C (100) to make 40 and 90.

can be placed before (50) and (100) to make 40 and 90. C can be placed before D (500) and M (1000) to make 400 and 900.

Given a roman numeral, convert it to an integer.

Example 1:

Input: s = "III"

Output: 3

Example 2:

Input: s = "IV"

Output: 4

Example 3:

Input: s = "IX"

Output: 9

Example 4:

Input: s = "LVIII"

Output: 58

Explanation: L = 50, V= 5, III = 3.

Example 5:

Input: s = "MCMXCIV"

Output: 1994

Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.

Constraints:
What are Arrays?
By: Aman Agarwal
Tags: Arrays, Data Structures, Java, Programming, Algorithms

Lets Answer #2

What are Arrays?

Photo by Luca Bravo on Unsplash

An array is a data structure that stores a bunch of similar typed data in a contiguous memory location. This means that the array elements can be traversed with the help of whole number indexing.

A visualization for Arrays. Picture source: Oracle.

Each data type takes a particular amount of memory. Some of the values are:

+----------------+----------------------------+

| Data types | Memory Occupied(in Bit) |

+----------------+----------------------------+

| Boolean | 1 |

| Byte | 8 |

| Char | 16 |

| Short | 16 |

| Int | 32 |

| Long | 64 |

| Float | 32 |

| Double | 64 |

+----------------+----------------------------+

In C and C++, the size of Char is 8 Bit while in Java it is 16 bit as C and C++ use ASCII format and Java uses Unicode Format.

Calculation of address of each element

The formula for calculation of address of each element is

Address of nth element = Base Address +(n-1)*(size of data type)

where

n is the element you want the address for.

Base address is the address of element at first element

and size of data type refers to memory occupied by the data type.

When to use arrays:

When the order of data matters.

of data matters. When you know the number of elements and the number of elements is fixed .

and the number of . And when the elements are similarly typed. An array can only hold a single data type.

Note: In most of the languages, the index starts from 0 but in some languages, the index starts with one. So all the limits for the loops will change accordingly. Arrays are one of the most basic data structures and can be used to implement other data structures like Queue, stack, heap, etc.

Basic operations on Arrays

Here are some of the basic operations which can be performed on arrays:

In Java, the arrays are abstracted by the class called ArrayList. Using this class is beneficial as it provides various functions and helps you to write better code.

Traversing

Traversing means printing all the elements of a data structure.

Sorting

There are multiple ways to sort an array. Some of the most popular ways of sorting arrays are Bubble Sort, Selection Sort, Merge Sort, Quick Sort, Radix Sort, Heap Sort, Bucket Sort, and many more. Sorting will be covered in a separate article as it is a pretty huge topic.

Searching

Searching if the element is present in the array. If it is present, it will return the index, or else it will return -1

Reversing

Reversing the order of the arrays. This means that the last element will be swapped by the first element.

There are more operations like Insertion, Deletion, check if it is a palindrome, etc. They will be covered in subsequent articles.

Stay tuned for more articles and if in case you have missed the previous article on “Introduction to Data Structures”. Do check it out. The link to the article is here.
Dijkstra’s Algorithm Visualizer
By: Ganapathy P T
Tags: Pygame, Data Structures, Python, Dijkstra

— the mother of all path finding algorithm

What is Dijkstra’s Algorithm?

First of all let’s figure out what is Dijkstra’s Algorithm.Yeah the name sounds very weird. It is an path finding algorithm in a graph data structure. Confused of what a graph exactly is ? Graph is a data structure that stores the relation between two nodes (node can be anything that holds a data) for example: Consider Facebook — you can have as many friends and your friend can have the same. Ever thought hoe Facebook store the connection between the users — yes they use Graph Data Structure

How Does it Works?

Now let’s discuss how does the Algorithm works. Consider a graph with weighted edges (the line that connects two nodes is an edge) as shown below

Graph example

Let’s say you are at position 0 and you want to go to position 4. You can easily trace the shortest path to go from position 0 to position 4. But Computers are like child we need to feed them everything. Let’s plot a table to understand the steps involved in the algorithm.

table 1

Considering the 0th position as the starting node we make the distance as 0 (of course the distance from x to x is always gonna be zero). For the case of algorithm we make all other distances as infinity.

Now we want to choose a neighboring nodes of the current node (node 0). The order is not a matter.

currentNode = 0, consideringNode = 1

dist(consideringNode) = dist(currentNode) + weight

here weight is the number on the edge between the current node and the consideringNode. After calculating the distance of the node considered, if the distance is lesser than the existing distance in the table for that particular node, then we replace the value (this is the reason why we use infinity as default distance so that any distance at first will be lesser than infinity). Now consider the second neighbor of the currentNode and do the same.

(note: we need to store the visited node somewhere so that we don’t iterate over the same node which was already visited)

After updating the values of the distance of every neighbors of the current node, add the current node as the from column for all the neighboring nodes. After the traversal of first node the table should look like this:

table 2

Consider the nodes which are not yet visited and pick the node which as the shortest distance in the table. In this example, node 1 has the lowest distance among all the non visited nodes (note that the node 0 is visited). So picking that one up and do the same process until there is no non visited node in the graph. Now the table will be like this one:

table 3

Thus the algorithm, yes you read that right. That’s all for the algorithm. You can use this table to find any shortest distance from node 0 to any other node. For example: let’s say we need to visit the node 4 from node 0, to find the shortest path, we need to backtrack from the node 4. Refer the row of which the node 4 lies. It comes from 5, now look at 5 it comes from 6, repeat that until you get to node 0 (the source). Thus the path will be:
Python Data Structures
By: Poby S Home
Tags: Python, Python Data Structures, Software Engineering, Programming, Data Structure

Built-in Data Types

List []

indexed

ordered (insertion order)

changeable

allows duplicate values.

myList = [1,'two', [3.0, "four"]]

List Methods

Dictionary {}

Dictionaries are used to store data values in key:value pairs.

unordered

changeable

does not allow duplicates.

myDict = {1: 'Java', 2: 'C++', 'three':'Python', 'four':4 }

Tuple ()

Tuples are the same as lists with the exception that the data once entered cannot be changed. Immutable!

ordered (insertion order)

Unchangeable

allow duplicates

thistuple = ("apple", "banana", "cherry", "apple", "cherry")

print(thistuple)

// ('apple', 'banana', 'cherry', 'apple', 'cherry')

Sets

Does not allow duplicate values

Unordered

Unindexed

Unchangeable
[Leet Code] Longest Continuous Increasing Subsequence
By: Matthew Boyd
Tags: Leetcode, Data Structures, Leetcode Solution, Algorithms, Leetcode Easy

Problem:

Given an unsorted array of integers nums , return the length of the longest continuous increasing subsequence (i.e. subarray). The subsequence must be strictly increasing.

A continuous increasing subsequence is defined by two indices l and r ( l < r ) such that it is [nums[l], nums[l + 1], ..., nums[r - 1], nums[r]] and for each l <= i < r , nums[i] < nums[i + 1] .

Example 1:

Input: nums = [1,3,5,4,7]

Output: 3

Explanation: The longest continuous increasing subsequence is [1,3,5] with length 3.

Even though [1,3,5,7] is an increasing subsequence, it is not continuous as elements 5 and 7 are separated by element

4.

Example 2:

Input: nums = [2,2,2,2,2]

Output: 1

Explanation: The longest continuous increasing subsequence is [2] with length 1. Note that it must be strictly

increasing.

Constraints:

0 <= nums.length <= 104

-109 <= nums[i] <= 109

Solution:
Leetcode #98 (validate binary search tree)
By: Anthony Mendoza
Tags: JavaScript, Binary Search Tree, Leetcode, Data Structures, Algorithms

Thoughts / Questions

Some things to keep in mind if you were asked this during an interview.

Questions

1. What would the output need to be (this case leetcode gives it to use and it is a boolean. )

2. I would if possible draw out a BST and a tree to confirm the question.

3. What are we given in the function. ( head, value, left, right?)

Thought process

* For this Problem I want to first traverse the tree inOrder and add the values to an array. By doing this we will have all the values in order.

* Next I want to run a loop to check if the value at our current index is bigger or equal to the next value. if it is we return false because we know this is not a valid BST.

With InOrder Our output will be in order. Meaning we are grabbing the lowest value first and working our way up.

* Looking at the picture above you can see if a value before hand is bigger there is no way this is a valid BST.
Though I’ve been trying to learn about Data Structures and Algorithms for a while now but this …
By: Desmond Ngwuta
Tags: Data Structures, Algorithms

Though I’ve been trying to learn about Data Structures and Algorithms for a while now but this , this made my day. Thank you for making it easy to understand.
Dynamic Programming, Part 2–1
By: Poby S Home
Tags: Recursion, Dynamic Programming, Programming Interviews, Algorithm, Data Structure

Example of Dynamic Programming, Part 1

This is a note I took while taking Avik Das’ Dynamic Programming course at Linkedin Learning. His course is awesome and I highly recommend it!

Flowerbox problem

Goal: Maximize the total height of all planted flowers.

Example solution

Maximized total height, 12

Maximized total height, 18

Fundamental problem

Mathematical form

f(n-1) because of 0 index start

solution in python
[Leet Code] Student Attendance Record I
By: Matthew Boyd
Tags: Leetcode, Data Structures, Leetcode Solution, Algorithms, Leetcode Easy

Leetcode: https://leetcode.com/problems/student-attendance-record-i/

Problem:

You are given a string representing an attendance record for a student. The record only contains the following three characters:

‘A’ : Absent. ‘L’ : Late. ‘P’ : Present.

A student could be rewarded if his attendance record doesn’t contain more than one ‘A’ (absent) or more than two continuous ‘L’ (late).

You need to return whether the student could be rewarded according to his attendance record.

Example 1:

Input: "PPALLP"

Output: True

Example 2:

Input: "PPALLL"

Output: False

Solution: