Skip to content

Instantly share code, notes, and snippets.

@ms1797
ms1797 / n_queen_problem.cpp
Created October 29, 2018 21:46
famous_n_queen_problem
#include <bits/stdc++.h>
using namespace std;
/**
* Given nxn board place n queen on this board so that they dont attack each other. One solution is to find
* any placement of queens which do not attack each other. Other solution is to find all placements of queen
* on the board.
*
* Time complexity O(n^n)
* Space complexity O(n*n)
@ms1797
ms1797 / maxproduct_interviewBit.cpp
Last active October 20, 2018 19:29
Solution to a good question on InterviewBit with Problem Statement
/*Problem Statement::MAXPPROD_INTERVIEWBIT
You are given an array A containing N integers. The special product of each ith integer in this array is
defined as the product of the following:<ul>
LeftSpecialValue: For an index i, it is defined as the index j such that A[j]>A[i] (i>j).
If multiple A[j]’s are present in multiple positions, the LeftSpecialValue is the maximum value of j.
RightSpecialValue: For an index i, it is defined as the index j such that A[j]>A[i] (j>i).
If multiple A[j]s are present in multiple positions, the RightSpecialValue is the minimum value of j.
@ms1797
ms1797 / largestRectangleInHistogram.cpp
Last active October 20, 2018 19:29
find area of largest histogram using stack
/*Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1,
find the area of largest rectangle in the histogram.
Largest Rectangle in Histogram: Example 1
Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].
Largest Rectangle in Histogram: Example 2
The largest rectangle is shown in the shaded area, which has area = 10 unit.
@ms1797
ms1797 / InfixToPostfix.cpp
Last active September 11, 2022 11:43 — forked from mycodeschool/InfixToPostfix.cpp
Infix to Postfix conversion in C++ using stack. We are assuming that both operators and operands in input will be single character.
/*
Infix to postfix conversion in C++
Input Postfix expression must be in a desired format.
Operands and operator, both must be single character.
Only '+' , '-' , '*', '/' and '^' (for exponentiation) operators are expected.
*/
#include<iostream>
#include<stack>
#include<string>