Cycle detection in directed and undirected graphs

DFS approach to detect cycle in directed and undirected graphs
Leetcode - Quick 75 problems refresher
It contains categorised list of top 75 problems from leetcode.
Backtracking problems made easy
A simplified way of solving and understanding backtracking problems.
Javascript tricky interview questions

It is a curated list of some tricky JS questions generally asked in interviews.
CSV to SQL import using Node, Express and React
This is a simple application that gives an idea of how to creak a bulk import of csv files to SQL database.
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.
LeetCode: 169 Majority Element
LEETCODE : 169. Majority Element Link
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 .
LEETCODE : 171. Excel Sheet Column Number
LEETCODE : 171. Excel Sheet Column Number Link
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 :
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.
Tricky frontend questions
It contains some of the interview questions that are asked to React developers these days.
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.
HackerRank(greedy): Minimum Absolute Difference in an Array
Problem:
Consider an array of integers, A = a0, a1, a2….an-1. We define the absolute difference between two elements, ai and aj
(where ai not equal to aj ), to be the absolute value of ai-aj.
Given an array of n 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).
CodeVita 2017 Round-1 Problem-B
Problem : Concatenating primes
If you like numbers, you may have been fascinated by prime numbers. Sometimes we obtain by concatenating two primes. For
example, concatenating 2 and 3, we obtain the prime 23. The aim is to find all such distinct “concatenated primes” that could
be obtained by concatenating primes ≤ a given integer N.
Input Format:
Integer N
Output Format:
M, the number of distinct primes that could be obtained by concatenating two primes ≤ N
TCS-Codevita 2017 Round-1 Problem-A
**Problem : **Mountain peak sequence
Consider the first three natural numbers 1, 2, 3. These can be arranged in the following ways: 2, 3, 1 and 1, 3, 2. Inboth of
these arrangements, the numbers increase to a certain point and then decrease. A sequence with this property is called a
“mountain peak sequence”.
Given an integer N, write a program to find the remainder of mountain peak arrangements that can be obtained by rearranging
Codechef SEPT17 CookOff - Subsequence Equality Problem Code: LIKECS01
Problem: (Link: https://www.codechef.com/problems/LIKECS01 ) Chef Tobby is playing a rapid fire with Bhuvan. He gives Bhuvan a string S and each time, Bhuvan has to guess whether there exists 2 equal subsequences in the string or not.
Bhuvan got a perfect score in the game with Chef Tobby. However, Chef Tobby has now asked Bhuvan to write a program that will do this automatically given a string S. Bhuvan is an intelligent man but he does not know how to write a code.
Codechef - Courses in an university - Problem Code: UNICOURS
Problem There are n courses in a university being offered. These courses are numbered from 1 to n in the increasing order of their difficulty. For each course, you can have some courses as prerequisites. The prerequisite courses for a course should be of lower difficulty than it. You are given an array a of size n, where ai denotes that there should be at least ai prerequisite courses for i-th course.
Codechef MAY17 chef and his daily routine ( code: CHEFROUT )
Problem : https://www.codechef.com/problems/CHEFROUT Chef’s daily routine is very simple. He starts his day with cooking food, then he eats the food and finally proceeds for sleeping thus ending his day. Chef carries a robot as his personal assistant whose job is to log the activities of Chef at various instants during the day. Today it recorded activities that Chef was doing at N different instants. These instances are recorded in chronological order (in increasing order of time).
ProjectEuler -01 Multiple of 3 and 5
PROBLEM : https://www.hackerrank.com/contests/projecteuler/challenges/euler001
If we list all the natural numbers below that are multiples of or , we get and . The sum of these multiples is .
Find the sum of all the multiples of or below .
Input Format
First line contains that denotes the number of test cases. This is followed by lines, each containing an integer, .
Constraints
Output Format
CodeChef SEPT17 Sereja and Commands (code: SEACO)
Problem: Little Chef and Sum
https://www.codechef.com/SEPT17/problems/SEACO
Sereja has an array A consisting of n integers. Initially, all the elements of array are zero.
Sereja writes down m commands on a piece of a paper. The commands are enumerated from 1 to m. These commands can be of the following two types of commands:
l r (l ≤ l ≤ r ≤ n) — Increase all elements of the array by one, whose indices belongs to the range [l, r] l r (1 ≤ l ≤ r ≤ m) — Execute all the commands whose indices are in the range [l, r].
CodeChef SEPT17 Chef and Pick Digit (code: CHEFPDIG)
Problem: Little Chef and Sum
https://www.codechef.com/SEPT17/problems/CHEFPDIG
Chef likes to play with big numbers. Today, he has a big positive integer N. He can select any two digits from this number (the digits can be same but their positions should be different) and orders them in any one of the two possible ways. For each of these ways, he creates a two digit number from it (might contain leading zeros). Then, he will pick a character corresponding to the ASCII value equal to this number, i.
CodeChef SEPT17 Little Chef and Sum ( code: CHEFSUM)
Problem: Little Chef and Sum
https://www.codechef.com/SEPT17/problems/CHEFSUM
Our little chef is fond of doing additions/sums in his free time. Today, he has an array A consisting of N positive integers and he will compute prefix and suffix sums over this array.
He first defines two functions prefixSum(i) and suffixSum(i) for the array as follows. The function prefixSum(i) denotes the sum of first i numbers of the array. Similarly, he defines suffixSum(i) as the sum of last N - i + 1 numbers of the array.
CodeChef SEPT17 Problem: MINPERM
Problem:Minimum Good Permutation
A permutation of length n is an array of size n consisting of n distinct integers in the range [1, n]. For example, (3, 2, 4, 1) is a permutation of length 4, but (3, 3, 1, 4) and (2, 3, 4, 5) are not, as (3, 3, 1, 4) contains duplicate elements, and (2, 3, 4, 5) contains elements not in range [1,4].
A permutation p of length n is good if and only if for any 1 ≤ i ≤ n, pi ≠ i.
CodeChef SEPT17 Problem: CHEFSUM
Problem: Little Chef and Sums
Our little chef is fond of doing additions/sums in his free time. Today, he has an array A consisting of N positive integers and he will compute prefix and suffix sums over this array.
He first defines two functions prefixSum(i) and suffixSum(i) for the array as follows. The function prefixSum(i) denotes the sum of first i numbers of the array. Similarly, he defines suffixSum(i) as the sum of last N - i + 1 numbers of the array.
CodeChef (AUG17 LunchTime) : Mathison and pangrams - MATPAN
Problem: Mathison and pangrams
Mathison recently inherited an ancient papyrus that contained some text. Unfortunately, the text was not a pangram. Now, Mathison has a particular liking for holoalphabetic strings and the text bothers him. The good news is that Mathison can buy letters from the local store in order to turn his text into a pangram.
However, each letter has a price and Mathison is not very rich. Can you help Mathison find the cheapest way to obtain a pangram?
HackerRank - 101 Hack 51 - Fair Cake Cutting
Problem: Fair Cake Cutting
Leha is a young man from Belarus. He loves cakes really much. In Leha’s country, cakes are always evenly divided between people.
Leha wants to know how many people he should invite to his party if he has a cake whose size is equal to units and he wants each person to get exactly units of cake. Note that Leha doesn’t take a piece for himself; in other words, the cake is only divided among the people he invited to the party.
TCS Code Vita 6 ( problem-B )
Problem : Concatenating primes
If you like numbers, you may have been fascinated by prime numbers. Sometimes we obtain by concatenating two primes. For example, concatenating 2 and 3, we obtain the prime 23. The aim is to find all such distinct “concatenated primes” that could be obtained by concatenating primes ≤ a given integer N.
**
Input Format:**
Integer N
Output Format:
M, the number of distinct primes that could be obtained by concatenating two primes ≤ N
Codechef Probem : NITIKA
Problem : Link: ( https://www.codechef.com/JULY17/problems/NITIKA )
Nitika was once reading a history book and wanted to analyze it. So she asked her brother to create a list of names of the various famous personalities in the book. Her brother gave Nitika the list. Nitika was furious when she saw the list. The names of the people were not properly formatted. She doesn’t like this and would like to properly format it.
HackerRank Problem : Min Max Sum ( easy )
Problem : ( Link : Click here to visit this HackerRank problem page.)
Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.
Input Format
A single line of five space-separated integers.
Constraints
Each integer is in the inclusive range .
HackerRank Problem : Reverse and capitalise first alphabet of each word.
* Problem : (Link : Click here to visit this problem on HackerRank. )
*
Reverse the words in a string and capitalize the first letter of each reversed word, preserving the capitalization in the original stri. For eg: “Hello World” would be transformed to “OlleH DlroW”.
Input :
The first line of input would be the number of test cases followed by each string in a line.
Output :
A Simple C program to convert DECIMAL to BINARY
A Simple C program to convert DECIMAL to BINARY
1#include<iostream>
2#include<stdio.h>
3using namespace std;
4int main()
5{
6int n, arr[100] ;
7int i=0,j;
8cout<<“Enter the decimal number —>” ;
9cin>>n;
10// using while loop to store in arr[]
11while( (n/2) >=1)
12{
13arr[i++]= (n%2);
14n=n/2;
15}
16if(n==3)
17{
18arr[i++]=1;
19arr[i]=1;
20}
21else if(n==2)
22arr[i]=0;
23else if(n==1)
24arr[i]=1;
25
26cout<<endl ;
27for(j=i;j>=0;j–)
28cout<<arr[j];
29
30return 0;
31}
OUTPUT
Make USB flash drive a bootable media via Command Prompt
Follow the following steps :- Step I : Open command prompt as administrator
Step II: Type “diskpart” and hit enter
Step III: Type “list disk” and then press enter.
Step III: Check the disk number of you USB drive. ( in example it is 1 )
Step IV: Now, type “select disk 1” and then hit enter ( remember here 1 is the disk number)
Step V: `Now type “clean” and hit enter.
Bypass Windows User Login
Bypass Microsoft Windows User Login Step I :Get any Linux Distribution live bootable disk (generally all Linux Distros comes with live boot option).
If you don’t have bootable disk download it from the respective website. Although Ubuntu is most popular Linux distribution. You can download Ubuntu from :http://www.ubuntu.com/download/desktop( select the latest version according to your cpu artitecture viz. 32 bit or 64 bit). After download, you can burn it DVD or a USB flash drive).

