Problem Statement Given two arrays, write a function to compute their intersection.The result can be in any order. Each element in the result should be unique
Here is the LeetCode link to the problem: 349. Intersection of Two Arrays
Runtime for this solution is 52 ms.
Test Cases: Example 1:
Input: nums1 = [1,2,2,1], nums2 = [2,2]
Output: [2]
Example 2:
Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
Output: [9,4]
Read more
Problem Statement There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
Here is the leetcode link to the problem: LeetCode: Median of Two Sorted Arrays
What is a median?
StatTrek defines median as a measure of central tendency. Simply explained In an array of odd values median will be middle value.
Read more
Introduction A user agent makes a CORS request when it requests resource from a different domain, protocol or port. It is restricted on most browsers for security reasons, XMLHttpRequest and the Fetch API both follow same origin policy
Same Origin Policy
There is no single same origin policy.However, let us try to define some basics:
What is Origin ? According to RFC 6454 user-agents group URIs together into protection domains called origin.
Read more
Introduction Recently, I needed to create a php webservice which any application could connect to and it would return a JWT auth token authorizing you. Here, I retrace my steps as well as share basic barebones code for such a webservice
Url First of all we needed a url we can hit so, I added a domain name to my /etc/hosts file
sudo vim /etc/hosts Added below entry to the file 127.
Read more
Introduction Best way to define something is to look at examples, so here are a few examples of events [Context is limited to web]:
User presses a key on keyboard Error Occured Api returned data Web page finished loading Event interface represents any event which happens in DOM, there are many types of events and they use different interfaces. Some of these interfaces are based on main Event interface, which contains common properties and methods for all events.
Read more
Background Recently I needed to install and setup Postgres on my system for a side project. Here are the steps I followed to get it working on my machine.
## Check For Version Installed: lsb_release -a It will give you output like this. Once this is done we run:
$ sudo apt-get update $ sudo apt-get install postgresql postgresql-contrib Click enter when prompted.
Postgres uses "roles" to handle authorization.
Read more
Introduction When I decided to build my personal website, there were options abound on how to build, how to deploy etc. I came across hugo and netlify on twitter and everyone raved about how easy it was. So, I decided to get a basic website up and running first and then go about tweaking and moving it. Found the process to be really smooth, documenting it here for future reference as well as for someone else who might want to use it.
Read more