This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int maxSubarrProd(int arr[], int size) | |
{ | |
int maxProd = 0; | |
int currProd = 0; | |
int i; | |
for (i = 0; i < size; i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
/* | |
House thief using recursive approach. | |
either pick current house or pick next house. | |
maximize both results. | |
*/ | |
int houseThiefRec(int inp[], int size, int curIdx) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
struct Item | |
{ | |
int weight; | |
int cost; | |
Item() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
/* | |
Activity selection (or) | |
Interval scheduling maximization problem. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int findCombinations(int coins[], int n, int amount, int currentCoin) | |
{ | |
if (amount == 0) | |
{ | |
return 1; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <unordered_map> | |
using namespace std; | |
int findMaxOccurMap(int arr[], int n) | |
{ | |
unordered_map<int, int> map; | |
for (int i = 0; i < n; i++) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <list> | |
#include <stack> | |
using namespace std; | |
class Vertex | |
{ | |
public: | |
Vertex(int val) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int min(int a, int b, int c) | |
{ | |
int min = a; | |
if (min > b) | |
{ | |
min = b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int quickSortUtil(int inp[], int start, int end) | |
{ | |
int elm = inp[end]; | |
int result = start - 1; | |
for (int i = start; i < end; i++) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int maxSubArraySum(int arr[], int size) | |
{ | |
int sum = 0; | |
int maxSum = INT_MIN; | |
int i; | |
for (i = 0; i < size; i++) |