Skip to content

Instantly share code, notes, and snippets.

View Ajay35's full-sized avatar

Ajay Subhash Jadhav Ajay35

  • Oracle
  • Hyderabad
View GitHub Profile
/*
// Definition for a Node.
class Node {
public:
int val;
vector<Node*> children;
Node() {}
Node(int _val) {
/*
// Definition for a Node.
class Node {
public:
int val;
vector<Node*> children;
Node() {}
Node(int _val) {
TreeNode* searchBST(TreeNode* root, int val) {
while(root!=NULL)
{
if(root->val==val)
return root;
else if(root->val < val)
root=root->right;
else
root=root->left;
class Solution {
public:
vector<int> diStringMatch(string S) {
int n=S.size();
vector<int> ans(n+1);
int inc=0,dec=n;
for(int i=0;i<n;i++)
{
if(S[i]=='I')
ans[i]=inc++;
class Solution {
public:
int repeatedNTimes(vector<int>& A) {
int n=A.size();
for (int i = 0; i+2 < n ; i++)
{
if (A[i] == A[i + 1] || A[i] == A[i + 2])
return A[i];
}
return A[n - 1];
class Solution {
public:
vector<int> replaceElements(vector<int>& arr) {
int n=arr.size();
int cur=arr[n-1];
arr[n-1]=-1;
for(int i=n-2;i >= 0;i--)
{
int temp=arr[i];
arr[i] = cur;
class Solution {
public:
int countBalls(int lowLimit, int highLimit) {
vector<int> boxes(46);
int ans=0;
for(int i=lowLimit;i<=highLimit;i++)
{
int n=i,sum=0;
while(n>0)
{
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
class Solution {
public:
vector<int> sortArrayByParity(vector<int>& A) {
int i=0;
int j=A.size()-1;
while(i<j){
if(A[i]%2==0){
i++;
}else if(A[i]%2==1 && A[j]%2==0){
class Solution {
public:
vector<int> finalPrices(vector<int>& prices) {
// next smaller or equal number.
int n=prices.size();
stack<int> st;
for(int i=0;i<n;i++)
{
if(st.empty() or prices[st.top()] < prices[i])
st.push(i);