Skip to content

Instantly share code, notes, and snippets.

@luckypapa
luckypapa / xornecklace.c
Last active August 29, 2015 14:25
XOR Necklace
// A ^ B = A + B - 2(A&B) .....
// https://algospot.com/judge/problem/read/XORNECKLACE
// time complexity : O(n)
// space complexity : O(500)
#include <stdio.h>
#define MAX_SIZE 500
long long int xorNeclaceMaxValue(void) {
@luckypapa
luckypapa / findIntersectionFromSortedArray.cpp
Created July 12, 2015 08:10
No. 24 - Intersection of Sorted Arrays
//http://codercareer.blogspot.kr/2011/11/no-24-intersection-of-sorted-arrays.html
//timecomplexity : O(nlogm)
//spacecompexity : O(n)?
#include <vector>
#include <iostream>
#include <algorithm>
int arr1[7] = {1, 3, 5, 7, 9, 10, 15};
int arr2[5] = {3, 5, 7, 11, 16};
@luckypapa
luckypapa / lectureNote.cpp
Created July 5, 2015 02:16
Lecture Note solution
// https://algospot.com/judge/problem/read/LECTURE
// Time Complexity : O(nlogn)
// Space Complexity : O(n)
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
@luckypapa
luckypapa / findMissingNumberInArray.cpp
Created June 28, 2015 23:29
No. 37 - Missing Number in an Array - solution
// http://codercareer.blogspot.kr/2013/02/no-37-missing-number-in-array.html
// problem1 => time complexity : O(N), space complexity : O(2)
// problem2 => time complexity : O(logN), space complexity : O(3)
#include <iostream>
#include <assert.h>
using namespace std;
// https://algospot.com/judge/problem/read/JOSEPHUS
// time complexity O(kN)
// space complexity O(N)
#include <stdio.h>
#include <list>
using namespace std;
void findAlivePerson(int n, int k) {
@luckypapa
luckypapa / leftRotationOfString.c
Last active August 29, 2015 14:23
No. 19 - Left Rotation of String
//http://codercareer.blogspot.kr/2011/11/no-19-left-rotation-of-string.html
// time complexity : O(n)
// space complexity : O(n)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Reverse(char *pBegin, char *pEnd) {
if(pBegin == NULL || pEnd == NULL)
@luckypapa
luckypapa / find_turning_number.cpp
Last active August 29, 2015 14:22
No. 22 - Turning Number in an Array - solution
//http://codercareer.blogspot.kr/2011/11/no-22-turning-number-in-array.html
//timecost : O(logN)
#include <assert.h>
#include <stdio.h>
int findTurningNumber(int * array, int length) {
if (array == NULL || length <= 2)
return -1;
@luckypapa
luckypapa / findMaximumSumOfSubArray.cpp
Created May 29, 2015 07:19
No. 03 - Maximum Sum of All Sub-arrays - solution
//http://codercareer.blogspot.kr/2011/09/no-03-maximum-sum-of-all-sub-arrays.html
#include <stdio.h>
#include <algorithm>
#include <assert.h>
using namespace std;
int findMaximumSumOfSubArray(int *array, int length) {
if (array == NULL || length <= 0) {
printf("wrong input \n");
@luckypapa
luckypapa / getTransCount.cpp
Created May 23, 2015 02:51
No. 55 - Translating Numbers to Strings : solution
//http://codercareer.blogspot.kr/2014/09/no-55-translating-numbers-to-string.html
#include <iostream>
#include <string>
#include <assert.h>
using namespace std;
int getTransCount(string number) {
if (atoi(number.c_str()) <= 0)
return 0;
//http://codercareer.blogspot.kr/2013/02/no-44-maximal-stolen-values.html
#include <stdio.h>
#define ARRAY_MAX 10
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
int findMaxStolenValue(int *array, int size) {
if (size == 0)
return 0;