Category "data-structures"

Amazon interview: Min stack

I recently had my Amazon interview for SDE. I was asked to design a stack which does push, pop and min in O(1). I got the logic and implemented the push of the

An undirected graph having n edges, then find out no. of vertices that graph have?

An undirected graph having 'n' number of edges, then find out number of vertices that graph have?‏‏‎

Finding the shortest path with only passing specific edge less or equal to one time in Graph

Given a undirected graph that it has ordinary edges and specific edges, our goal is to find the sum of the shortest path's weight between two vertices(start ve

How to skip an item in nested map based on When()

I want iterate over items's data and create a a new list of SomeData based on item.type however when type is UNKNOWN I need skip that element and not add to lis

Fastes way to read a tsv file and store it in a map (C++)

I'm working on a project with 6 huge mapping tsv files. In most cases they look like this: First: ID which is a unique String which starts with a char and goes

export file to xlsx format in java

I am getting 500k records per request from the Database then mapping the data to a list of POJO classes then writing the records to an excel sheet (I have the r

How to do pre-order and post-order traversal of THREADED binary search tree?

Okay, so in-order traversal of threaded binary tree by using threads goes something like this: Start at leftmost node and print it Follow thread to right and

Infected Fish can eat another fish having size less that its own. Minimum number of operation required

An evil scientist has developed an injection that induces insatiable hunger in a fish. On giving this injection, a fish of size x can eat another fish of smalle

My check for whether a graph is a Binary Tree always returns false

I have this question that is medium level and couldn't even think on how to solve this problem, my solution could be overkill as I have no idea on how to traver

malloc(): memory corruption (fast)

I just started to learn data structure and getting an error when executing malloc(): memory corruption (fast) what can be the issue and how to resolve it? I h

What is the purpose of a Bloomier filter?

This question is about the Bloomier filter, which is not the same as a standard Bloom filter. I'm learning about the Bloomier filter and I don't see the advanta

How can I declare a structure in C++ without defining it?

I have been following a tutorial at cplusplus.com/doc/tutorial. Near the end of the Functions page, it discussed prototyping a function. Later on, I read about

How to check if a struct is NULL in C or C++

i have the following structure typedef struct { char data1[10]; char data2[10]; AnotherStruct stData; }MyData; for some reason the imple

HashMap should be unsorted but still sorts according to key

According to these: http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html Difference between HashMap, LinkedHashMap and TreeMap java beginner : How k

C# Traverse tree and find all unique hierarchy chains from root to leaf

I am working on a tree problem and not able to figure out how to solve the problem at hand. I've googled and also checked on SO, but could not find a suitable a

How to store sets of objects that have occurred together during events?

I'm looking for an efficient way of storing sets of objects that have occurred together during events, in such a way that I can generate aggregate stats on them

Inserting a key-value pair in a specified position of a JS Map object (akin to Array's .splice()) [duplicate]

Is there a way to performance-efficiently insert a key-value pair in a specific place of a Map object? The problem I'm trying to solve is sto

Find the Longest Subarray

Given an array of integers, what is the length of the longest subarray containing no more than two distinct values such that the distinct values differ by no mo

Nested for loop in Big Oh Complexity

for(int i = 0; i < n; i++) { for(int j = 0; j < i; j++){ // do swap stuff, constant time } } I read that single for loop is O(N) and trav

How to loop over all examples in a tensorflow DatasetV1Adapter?

I have a dataset of images saved in 97 .tfrecord-files. Each example includes image data as well as groundtruth data (classes and bounding boxes) for object det