Skip to content

Instantly share code, notes, and snippets.

View neerajkr's full-sized avatar

Neeraj Kumar neerajkr

View GitHub Profile
// Sample code to perform I/O:
#include<bits/stdc++.h>
using namespace std;
int query(int * tree, int l, int r, int ql, int qr, int index){
if(r <ql || qr<l){
return INT_MAX;
}
#include<iostream>
#include<string>
using namespace std;
class ReferenceCounter
{
private:
int ref_count{0};
@neerajkr
neerajkr / ActivitySel.cpp
Created May 16, 2017 09:36
Given N activities with their start and finish times. Select the maximum number of activities that can be performed by a single person, assuming that a person can only work on a single activity at a time.
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int t;
cin >>t;
while(t--){
@neerajkr
neerajkr / dice_throw.cpp
Created May 13, 2017 11:26
Given n dice each with m faces, numbered from 1 to m, find the number of ways to get sum X. X is the summation of values on each face when all the dice are thrown.
#include <iostream>
using namespace std;
int main(){
int t;
cin >>t;
while(t--){
int n,x,m;
@neerajkr
neerajkr / Zero_One_knapsack.cpp
Created May 13, 2017 11:24
You are given weights and values of N items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. Note that we have only one quantity of each item, In other words, given two integer arrays val[0..N-1] and wt[0..N-1] which represent values and weights associated with N items respectively. Also given an integ…
#include <iostream>
using namespace std;
int main()
{
//code
int t;
cin >>t;
while(t--){
@neerajkr
neerajkr / RopeCuttingMultiplication.cpp
Created May 12, 2017 15:01
Given a rope of length n meters, cut the rope in different parts of integer lengths in a way that maximizes product of lengths of all parts. You must make at least one cut. Assume that the length of rope is more than 2 meters.
#include <iostream>
using namespace std;
int main(){
int n;
@neerajkr
neerajkr / RodCutting.cpp
Last active May 12, 2017 14:56
Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n. Determine the maximum value obtainable by cutting up the rod and selling the pieces.
#include <iostream>
using namespace std;
int main(){
int n;
#include <iostream>
using namespace std;
void swap(int *a, int *b ){
int temp;
temp=*b;
*b=*a;
*a=temp;
}
@neerajkr
neerajkr / permut.cpp
Created May 11, 2017 18:35
216 - Getting in Line
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
using namespace std;
void swap(int *a,int *b);
void permut(int *x_corr, int *y_corr,int * permut_index, int left,int right,int n, int *Correct_index);