A data structure is a way of organizing data in a fashion that allows particular properties of that data to be queried and/or updated efficiently.

learn more… | top users | synonyms (1)

0
votes
0answers
11 views

Best algorithm to find a subarray whose sum is closer or equal to given number. [on hold]

Suppose we have sub array of size n and we have to find subarray of whose sum is equal to k or closest to k. Solution: What would be best algo for this problem.
1
vote
0answers
28 views

Deepest left leaf node in a binary tree

Given a Binary Tree, find the deepest leaf node that is left child of its parent. This question is attributed to GeeksForGeeks. Looking for code-review, optimizations and best practices. ...
6
votes
2answers
69 views

Flatten a multilevel linked list

Given such a structure the output should be ...
3
votes
1answer
39 views

Reverse values of alternate nodes of the tree

Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree. Given tree: ...
0
votes
0answers
23 views

Return the next right node

Given a binary tree, return the next right node. This question is attributed to GeeksForGeeks. For example, consider the following Binary Tree. Output for 2 is 6, output for 4 is 5. Output for 10, 6 ...
4
votes
1answer
29 views

Synchronized LinkedHashed map

I've written the following code ages ago (10+ years) which is part of a simple chat server. I'm going to refactor it a bit in java and then for fun I'm going to convert it to Scala and use Akka actors ...
1
vote
1answer
66 views

Get the levels of a binary tree

Given a binary tree, return a list of each level. I'm looking for a general review and a mention on best-practices, optimization, and verification of my complexities. Time complexity: \$O(n)\$ ...
0
votes
0answers
30 views

Nested maps vs. combined keys [migrated]

in the project I am currently working on we had three different types of prices depending on the age of the user (adult, child, etc...). So we had on the DB a table looking like this: ...
-1
votes
0answers
12 views

text-extractor [text based version] [closed]

I am using a Linux Debian 7.5 Wheezy. I made a program that could extract any text (even code) from a text. The process goes like this: ...
11
votes
2answers
1k views

A fraction of the code

Following up on this post, and including some major changes suggested, here's the revised code. Changes include: No longer keeping an IFormatProvider at instance ...
9
votes
1answer
138 views

Formattable Fraction

I have written this small little program, to test how my Fraction type behaves when used with and without a custom ...
1
vote
0answers
22 views

Following-up “given a two dimensional linked list, create a flattened sorted list”

A node has a next and down pointer. Merge the linked-list such that end result is sorted. Here we have a top level linked-list, followed by a down-list. If { 10 : {20, 30} , 35 { 40, 50 } ...
5
votes
2answers
57 views

Scoring matches of a game - reducing duplicated code

I'm writing a small application to score matches of a game. (There are two "teams" on each "alliance", and two alliances play each other in a match.) I have a "logic" class that handles the values of ...
2
votes
2answers
44 views

Merge N sorted list

Given n sorted lists, merge them. This is a fairly common question, attributed to plenty of interview question websites. I'm looking for code-review, optimizations and best practices. I'm also ...
10
votes
1answer
199 views

Find the peak stock price for each company from CSV data

During the hiring process, a company gave me this test: Q) Consider Share prices for a N number of companies given for each month since year 1990 in a CSV file. Format of the file is as below ...
12
votes
3answers
314 views

Memory-efficient string collection

My goal is to create a memory-efficient (immutable) collection of strings. The imagined use-case is checking for valid words in a Scrabble-like game. Wikimedia Commons has a pretty good summary of ...
6
votes
1answer
46 views

Sorted unidirectional list with add, delete and find

I am aware of the fact that a sorted unidirectional list has only very few use cases, but nevertheless, this python code feels fairly long for Python code. How can I improve it? ...
3
votes
3answers
174 views

Find all nodes in tree, without a sibling

Find all nodes of trees, without siblings. This question is attributed to GeeksForGeeks. I'm looking for code reviews, optimizations and best practices. ...
0
votes
3answers
117 views

Given a two dimensional linked list, create a flattened sorted list

A node has a next and down pointer. Merge the linked-list such that end result is sorted. Here we have a top level linked-list, followed by a down-list. If { 10 : {20, 30} , 35 { 40, 50 } } is the ...
1
vote
0answers
33 views

Find K distant nodes

Find all nodes, which are at a distance of k from the input node. Input: target = pointer to node with data 8. ...
5
votes
2answers
100 views

Queue over resizable array implementation

I study data structures on coursera's course, and there is an extra exercise to create a Queue data structure. I created it: ...
4
votes
3answers
134 views

Repeatedly skip M nodes then delete N nodes then skip M nodes and so on

Given a linked list and two integers M and N. Traverse the linked list such that you retain M nodes then delete next N nodes, continue the same until end of the linked list. Input: ...
-2
votes
1answer
89 views

Given a BST, transform it into greater sum tree

Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater than that node. Diagram is here. Looking for code review, optimizations and best practices. ...
1
vote
1answer
57 views

Sort a linkedlist with 3 elements 0, 1 and 2

Given a linked list of 0s, 1s and 2s, sort it. Looking for code review, optimizations and best practices ...
6
votes
2answers
78 views

Time Limit Exceeded with Segment Tree data structure

I am trying to solve this problem Chef Ceil has some matchsticks in his kitchen. Detail of matchsticks: There are N matchsticks in total. They are numbered from to 0 to N-1 inclusive. ...
6
votes
2answers
131 views

Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree

Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree. Given tree: ...
0
votes
0answers
33 views

Detect if a tree is complete binary tree

Detect if tree is complete binary tree. This question is improvement over previously asked here. Looking for code-review, optimizations and best practices. Verifying both space and time complexity to ...
2
votes
4answers
101 views

Maximum of all subarrays of size k

Given an array and an integer k, find the maximum for each and every contiguous subarray of size k. Examples: Input: ...
2
votes
2answers
49 views

Decide the start of the circular gas station path

Suppose there is a circle. There are n petrol pumps on that circle. You are given two sets of data. The amount of petrol that petrol pump will give. Distance from that petrol pump to the ...
5
votes
2answers
141 views

Find max-number div by three to be formed by array elements

Given an array of non-negative integers, find the largest multiple of 3 that can be formed from array elements. For example, if the input array is {8, 1, 9}, the output should be "9 8 1", and ...
6
votes
4answers
144 views

Stack with 'getMinimum' operation

Design a Data Structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return minimum element from the ...
4
votes
1answer
47 views

Stack with “getMiddle” and “deleteMiddle” operation

Looking for code review, optimizations and best practices. ...
4
votes
2answers
91 views

Implement queue using linkedlist

Implement queue using linkedlist. Looking for code review, optimizations and best practices. ...
4
votes
1answer
69 views

Detect a complete binary tree

Detect if a tree is complete binary tree or not. Looking for code review, optimizations and best practices. ...
4
votes
1answer
37 views

Implement stack using a linked list

I am trying to implement Stack using a linked list. Looking for code-review, best practices and optimizations. ...
4
votes
1answer
46 views

Counting inversions

Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion ...
3
votes
1answer
97 views

Model Implementation That Calls RESTful API

I am working on a ground-up rebuild for an app that has a relatively simple purpose. Users can view/favorite entities that are backed by a RESTful API. I own both the client code as well as the API. ...
5
votes
2answers
98 views

Adding features to a strategy game

I'm working on a basic strategy game for iOS and I have a question about the overall layout of the code in the program. I added some features to the game today and I had to add code to several ...
3
votes
2answers
143 views

How is my Java code for stack implementation?

The following example shows how to implement stack by creating user defined push() method for entering elements and pop() method ...
4
votes
0answers
69 views

Scala heap implementation

I'm a Scala beginner, so it'd be great if anyone would be so kind to give some feedback. ...
4
votes
1answer
322 views

Queued Employees

The following example shows how to implement a queue in an employee structure. I am looking for a review of the implementation: ...
2
votes
2answers
64 views

Two-dimensional array allocation in Go

I am creating a two-dimensional array, which I am going to process later in ways similar to image MinFilter, procedural labyrinth generation, etc. -- implying using coordinates and neighbors. Here ...
4
votes
1answer
75 views

Segment tree implementation

I'm learning segment trees and their implementation. For the purpose, I tried solving the problem on CodeChef. Full code here My tree implementation is as follows: ...
5
votes
1answer
51 views

Microcontroller ringbuffer

I'm pretty new to microcontrollers and C in general, so I thought asking here would be a good way not to get started with bad habits. ...
2
votes
1answer
55 views

Reading a binary file into object propery [closed]

I have a sequence of lines: ...
2
votes
1answer
49 views

M coloring problem

Given an undirected graph and a number m, determine if the graph can be colored with at most m colors such that no two adjacent vertices of the graph are colored with same color. Here coloring of a ...
1
vote
3answers
61 views

Optimization and accepted paradigms

This project was completed as part of an interview challenge. The feedback I received was: The code is neither optimized nor does it follow generally accepted paradigms, naming conventions or best ...
4
votes
0answers
81 views

Binary Search Tree Monad Implementation

I've written a Binary Search Tree Monad in Scala. I would like to hear your thoughts on how to improve it (e.g. making insertion/deletion/search faster and more scalable). Also, is there a better way ...
9
votes
3answers
188 views

Calculating infix expression with no parenthesis

This is my Java implementation (\$O(n)\$) about how to calculate infix expression with no parenthesis. For example, when we input "3 + 4 * 4 / 8", we will get a double type answer is 5.0. Here to ...
0
votes
2answers
96 views

Stack implementation using a queue

I've implemented a stack using a queue. Time complexity: \$O(n)\$ - push(), where n is the number of elements in the queue \$O(1)\$ - ...