This file contains 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
////////////////////////////////////////// | |
// std::unique_ptr usage | |
// - factory function return type for | |
// objects in a hierarchy. | |
////////////////////////////////////////// | |
////////////////////////////////////////// | |
// factory function with custom deleter | |
////////////////////////////////////////// | |
class Investment |
This file contains 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
// problem : https://www.hackerrank.com/challenges/special-palindrome-again/problem | |
long substrCount(int n, string s) { | |
long count = 0; | |
// 1st pass | |
vector<pair<char, int>> v; | |
char cur = 0; | |
for( auto ch : s ) | |
{ |
This file contains 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
// problem : https://www.hackerrank.com/challenges/fraudulent-activity-notifications/problem | |
int activityNotifications(vector<int> expenditure, int d) { | |
const int MAX_EXPENSE = 200; | |
const bool isEven = ( d % 2 ) == 0; | |
const int medianIndex = isEven ? ( d / 2 ) - 1 : d / 2; | |
// setup counting sort | |
vector<int> expenditureCounter( MAX_EXPENSE + 1, 0 ); |
This file contains 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 <cassert> | |
#include <pthread.h> | |
using namespace std; | |
int g_Count = 0; | |
void *thread( void *vargp ) | |
{ | |
for( int i = 0; i < 1000; ++i ) |
This file contains 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
// https://www.geeksforgeeks.org/reverse-a-linked-list/ | |
#include <iostream> | |
#include <cassert> | |
using namespace std; | |
struct List | |
{ | |
List* next; | |
int data; |
This file contains 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; | |
class A | |
{ | |
public: | |
A() { cout << "A()" << endl; } | |
~A() { cout << "~A()" << endl; } | |
}; |
This file contains 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
// problem : https://www.hackerrank.com/challenges/count-triplets-1/problem | |
// solution : https://www.hackerrank.com/challenges/count-triplets-1/forum/comments/468507 | |
long countTriplets(vector<long> arr, long r) { | |
map<int,long> mp2, mp3; | |
//mp2 to hold count of needed values after this one to complete 2nd part of triplet | |
//mp3 to hold count of needed values to complete triplet | |
long count = 0; | |
for( long val : arr ) |
This file contains 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
// problem : https://www.hackerrank.com/challenges/sherlock-and-anagrams/problem | |
// solution : https://www.geeksforgeeks.org/count-total-anagram-substrings/ | |
// C++ program to count total anagram | |
// substring of a string | |
#include <bits/stdc++.h> | |
using namespace std; | |
// Total number of lowercase characters | |
#define MAX_CHAR 26 |
This file contains 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
// problem : https://www.hackerrank.com/challenges/crush/problem | |
// solution : https://www.hackerrank.com/challenges/crush/forum | |
long arrayManipulation(int n, vector<vector<int>> queries) { | |
vector<long> arr( n + 1, 0 ); | |
for( auto q : queries ) | |
{ | |
arr[ q[0] ] += q[2]; | |
This file contains 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
// https://www.geeksforgeeks.org/minimum-number-swaps-required-sort-array/ | |
int minimumSwaps( vector<int> arr ) { | |
pair< int, int > arrPos[ arr.size() ]; | |
for( size_t i = 0; i < arr.size(); ++i ) | |
{ | |
arrPos[ i ].first = arr[ i ]; | |
arrPos[ i ].second = i; | |
} | |
sort( arrPos, arrPos + arr.size() ); |
NewerOlder