Posts

CSV to SQL import

Image
CSV to SQL import Link :   https://tinyurl.com/csv-sql-import Github :  https://github.com/krishankantray/csv-to-sql-import-client           https://github.com/krishankantray/csv-to-sql-import-server What is this app all about ? This app allows users to import a .csv file and save it in MySQL. The .csv file needs to be in a specified format, something like   this  . Once the data is saved we can see and delete the table data on the front-end. Whats there on back-end and front-end ? Back-End : NodeJS ExpressJS MySQL Front-End : ReactJS Here is the table structure : Field           Type --------------------------- id         int(11) level_col varchar(255) cvss         varchar(255) title         varchar(255) vulnerability varchar(255) solution varchar(255) reference_col varchar(255) Where is it deployed ? Client side app ( React app ) is deployed on  Netlify Server side app ( Node app ) is deployed on  Heroku MySQL datab

Kadane's Algorithm

Kadane's Algorithm TL;DR This algorithm is used to find maximum sum sub-array from a given array.  Its has O(n) time complexity and O(1) space complexity.   It works irrespective of whether the elements are positive or negative, whether sorted or unsorted.  Its DP approach Its brute force approach takes O(n^2) as it calculates all possible sub-array and then return maximum out of them.  Since brute force approach is very obvious and easy to implement, so, I am not discussing it here. Lets directly jump to Kadane's Algorithm :  Its uses two variables one stores local maximum ( local_maximum ) and other stores global maximum ( global_maximum ) . Initialise , local_maximum = 0 and global_maximum = -Infinity  We start iteration from the first element, and for each element we check following condition before updating the local_maximum : if  local_maximum < 0 ,  then local_maximum = arr[i] ,  this is because if local_maximum is negative value the

LeetCode: 169 Majority Element

LEETCODE : 169. Majority Element Link :  https://leetcode.com/problems/majority-element/ Problem Description :  Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element always exist in the array. For example: Example 1: Input: [3,2,3] Output: 3   Example 2: Input: [2,2,1,1,1,2,2] Output: 2       ______________________________________________________________________________     Explaination :  There is pretty easy way to solve it by using count of every element and then returning the element which has count greater than n/2 . But this solution comes with a cost of O(n) time and O(n) space.  There is a better solution which can do the job in O(n) time and O(1) space. Atleast we are saving some of the space.  How does our space efficient algorithm works ? Basically, what we do is that we go

LEETCODE : 171. Excel Sheet Column Number

LEETCODE : 171. Excel Sheet Column Number Link : https://leetcode.com/problems/excel-sheet-column-number/ Problem Description :  Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... Example 1: Input: "A" Output: 1     Example 2: Input: "AB" Output: 28 Example 3: Input: "ZY" Output: 701       ______________________________________________________________________________ Explaination :  Initially it looks like a hard problem but when we get to know the logic behind it then it seems to be a really easy problem. The observation needed here is that, the column title value represents a number of base 26. And all we need to do is to convert that base 26 number to base 10 number. To convert the base to base 10, we need to do what we usually do for binary or oc

CodeChef : Breaking Bricks || Problem Code: BRKBKS

CodeChef : https://www.codechef.com/JAN20B/problems/BRKBKS Problem: For her next karate demonstration, Ada will break some bricks. Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are W1,W2,W3. Ada's strength is S. Whenever she hits a stack of bricks, consider the largest k≥0 such that the sum of widths of the topmost k bricks does not exceed S; the topmost k bricks break and are removed from the stack. Before each hit, Ada may also decide to reverse the current stack of bricks, with no cost. Find the minimum number of hits Ada needs in order to break all bricks if she performs the reversals optimally. You are not required to minimise the number of reversals. Input The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first and only line of each test case contains four space-separated integers S, W1, W2 and W3. Output For each test case, pri
MVC ( Model View Controller ) Model : This is pure data. For eg: Database View : This user interface or visible data. For eg: Front-end of a webpage. Controller: Logic of the application. For eg: PHP page or node page of a website.

CodeChef OCT17 : Problem Code: PERFCONT

Problem: Chef wants to organize a contest. Predicting difficulty levels of the problems can be a daunting task. Chef wants his contests to be balanced in terms of difficulty levels of the problems. Assume a contest had total P participants. A problem that was solved by at least half of the participants (i.e. P / 2 (integer division)) is said to be cakewalk difficulty. A problem solved by at max P / 10 (integer division) participants is categorized to be a hard difficulty. Chef wants the contest to be balanced. According to him, a balanced contest must have exactly 1 cakewalk and exactly 2 hard problems. You are given the description of N problems and the number of participants solving those problems. Can you tell whether the contest was balanced or not? Input The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two space separated integers, N, P denoting the number of problems, number of

HackerRank(greedy): Minimum Absolute Difference in an Array

Problem:  Consider an array of integers, . We define the absolute difference between two elements, and (where ), to be the absolute value of . Given an array of integers, find and print the minimum absolute difference between any two elements in the array. Input Format The first line contains a single integer denoting (the number of integers). The second line contains space-separated integers describing the respective values of . Constraints Output Format Print the minimum absolute difference between any two elements in the array. Sample Input 0 3 3 -7 0 Sample Output 0 3 Explanation 0 With integers in our array, we have three possible pairs: , , and . The absolute values of the differences between these pairs are as follows: Notice that if we were to switch the order of the numbers in these pairs, the resulting absolute values would still be the same. The smallest of these possible absolute differ