Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
13
Indexable
Never
#include <iostream>
using namespace std;


void findAllCombinations(int * arr, int n, int start){
	
	/
	
	// fill 2*n array
	for(int i=0; i<2*n; i++){
		
		if(arr[i] == 0 && i+start+1 < 2*n && arr[i+start+1] == 0){
			arr[i] = start;
			arr[i+start+1] = start;
			
			findAllCombinations(arr, n, start+1);
		
			// backtrack
			arr[i] = 0;
			arr[i+start+1] = 0;
		}
	}
}

int uniquePaths(vector<vector<int, int> > grid, int r, int c, int i, int j){
	
	if(i == r || j==c) return 0;
	
	if(i == r-1 && j==c-1) return 1; // base case
	
	return uniquePaths(grid, r, c, i+1, j) + uniquePaths(grid, r, c, i, j+1);
}

int power(int a, int b){
	if(b==0) return 1;
	return a * power(a, b-1); // recursion
}

int powerIterative(int a, int b){
	int power = 1;
	for(int i=1; i<=b; i++){
		power = power * a;
	}
	return power;
}

void bubbleSort(int * arr, int n){
	
	if(n==1) return;
	
	// do it for a single pass
	for(int i=0; i<n-1; i++){
		if(arr[i] > arr[i+1]){
			swap(arr[i], arr[i+1])
		}
	}
	
	bubbleSort(arr, n-1); // recursive step
	
}

int main() {
	// your code goes here
	
	
	return 0;
}