Skip to content

Instantly share code, notes, and snippets.

View ajinkyajawale14499's full-sized avatar
🎯
Focusing

Ajinkya ajinkyajawale14499

🎯
Focusing
View GitHub Profile
@ajinkyajawale14499
ajinkyajawale14499 / histogram_dummy_zero.java
Created June 29, 2019 17:49
histogram dummy zero trick using stack
class Solution {
public:
int largestRectangleArea(vector<int>& height) {
height.insert(height.begin(),0); // dummy "0" added to make sure stack s will never be empty
height.push_back(0); // dummy "0" added to clear the stack at the end
int len = height.size();
int i, res = 0, idx;
stack<int> s; // stack to save "height" index
s.push(0); // index to the first dummy "0"
for(i=1;i<len;i++)
@ajinkyajawale14499
ajinkyajawale14499 / largest_histogram_stack.py
Created June 29, 2019 18:07
largest histogram solution using stack
def largestRectangleArea(self, height):
height.append(0)
stack = [-1]
ans = 0
for i in xrange(len(height)):
while height[i] < height[stack[-1]]:
h = height[stack.pop()]
w = i - stack[-1] - 1
ans = max(ans, h * w)
stack.append(i)
@ajinkyajawale14499
ajinkyajawale14499 / Largest_Histogram_stack2.java
Created June 29, 2019 18:27
Largest Histogram stack improvised solution
public class Solution {
public int largestRectangleArea(int[] height) {
int len = height.length;
Stack<Integer> s = new Stack<Integer>();
int maxArea = 0;
for(int i = 0; i <= len; i++){
int h = (i == len ? 0 : height[i]);
if(s.isEmpty() || h >= height[s.peek()]){
s.push(i);
}else{
@ajinkyajawale14499
ajinkyajawale14499 / Largest_Histogram_DP.java
Created June 29, 2019 18:47
Largest Histogram using dynamic programming
public static int largestRectangleArea(int[] height) {
if (height == null || height.length == 0) {
return 0;
}
int[] lessFromLeft = new int[height.length]; // idx of the first bar the left that is lower than current
int[] lessFromRight = new int[height.length]; // idx of the first bar the right that is lower than current
lessFromRight[height.length - 1] = height.length;
lessFromLeft[0] = -1;
for (int i = 1; i < height.length; i++) {
@ajinkyajawale14499
ajinkyajawale14499 / largest_histogram_divide&conquer.java
Created June 29, 2019 18:51
largest_histogram_divide&conquer
class Solution {
int maxCombineArea(const vector<int> &height, int s, int m, int e) {
// Expand from the middle to find the max area containing height[m] and height[m+1]
int i = m, j = m+1;
int area = 0, h = min(height[i], height[j]);
while(i >= s && j <= e) {
h = min(h, min(height[i], height[j]));
area = max(area, (j-i+1) * h);
if (i == s) {
++j;
@ajinkyajawale14499
ajinkyajawale14499 / stack.cpp
Created July 7, 2019 09:06
Shorten the string which same adjacent characters
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <stack>
using namespace std;
// logic is each time character is pushed over stack will be checked with following character if it same continue else print the char
void calculate(string str){
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from __future__ import absolute_import, division, print_function, unicode_literals
!pip install tf-nightly-gpu-2.0-preview
import tensorflow as tf
import os
import numpy as np
import matplotlib.pyplot as plt
_URL = "https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz"
zip_file = tf.keras.utils.get_file(origin=_URL,
fname="flower_photos.tgz",
extract=True)
base_dir = os.path.join(os.path.dirname(zip_file), 'flower_photos')
@ajinkyajawale14499
ajinkyajawale14499 / rescale.py
Created July 8, 2019 19:25
rescaling the images
IMAGE_SIZE = 224
BATCH_SIZE = 64
datagen = tf.keras.preprocessing.image.ImageDataGenerator(
rescale=1./255,
validation_split=0.2)
train_generator = datagen.flow_from_directory(
base_dir,
target_size=(IMAGE_SIZE, IMAGE_SIZE),