Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
6 votes
3 answers
495 views

Leetcode: Largest Number

I was trying out leetcode's Largest Number. As per the challenge's description: Given a list of non-negative integers nums, arrange them such that they form the largest number and return it. Since ...
ccot's user avatar
  • 361
3 votes
2 answers
411 views

Implementation of a market that matches bids to offers

This is my task: Each line in the file can be one of the following: Updates to the limit order book in the following format: ...
Данил Денк's user avatar
2 votes
1 answer
768 views

Traverse a list of tree nodes

I am wondering if there is a better way to traverse a list of trees. Here is my current algorithm: Collect the parent IDs in a Map Traverse all the groups and find ones where their ID is not in the ...
Mr. Polywhirl's user avatar
5 votes
2 answers
338 views

Data structure that retrieves each item with a specified probability

I wanted a data structure that allowed me to set the chances of randomly returning each of it's elements. For example, suppose I have a Human class. Every Human has an attribute called eyeColor. I ...
LuminousNutria's user avatar
2 votes
1 answer
135 views

Printing a K-ary tree stored in level-order in an array

I am given an array that represents a k-ary tree (I am also given the branching factor "k") that is stored in level order. My task was to print the tree in level order. For example a trinary tree ...
Prithvi Boinpally's user avatar
4 votes
2 answers
293 views

Binary Tree max sum conditionally

Problem : A binary tree is given as an input, each node of binary tree contains one integer value. Find the maximum sum of collection of nodes such that following two conditions are met. if node's ...
white_cat's user avatar
2 votes
1 answer
202 views

Building tree from edges puzzle with performance requirement

I'm working on a puzzle and have solved it, but my code is not fast enough to get the maximum score (if the code is faster than a certain achievable threshold, one gets awarded the maximum score). I ...
cactus's user avatar
  • 123
1 vote
2 answers
1k views

Preorder traversal of a tree

I am practising my coding skills on interviewbit. I got one question about preorder (for a tree). This is what I did first: ...
Ugnes's user avatar
  • 121
4 votes
1 answer
373 views

Construct binary tree from inorder and postorder traversal

The problem is taken from here. The tree is guaranteed not to have duplicate elements. My questions is, instead of creating new arrays leftInOrder, ...
Dabba raaju's user avatar
5 votes
1 answer
813 views

Red-black tree not matching performance of Java's TreeMap

This program is for constructing a symbol table where a key is a word and value is the frequency of the word in a text file and finding the word with maximum frequency. I did it in two ways: First I ...
Sumeet's user avatar
  • 309
9 votes
1 answer
887 views

Prefix trees for auto suggest

I wrote a quick prefix tree implementation. I know it may be far from perfect, but I need to make sure that I got the basics right. My main concerns are: Have I settled for the correct data ...
SarfarazSoomro's user avatar
4 votes
3 answers
6k views

Print all nodes from root to leaves

I've made a function to print all paths from root to all leaves in a binary search tree. I already have an insert function, which I haven't included in the code here as I felt it was irrelevant to the ...
B.oof's user avatar
  • 75
10 votes
1 answer
197 views

Good performance when predicting future game states

This question is about my answer to this king-of-the-hill challenge on Code Golf. In short, the purpose of the challenge is to code a slime that, trough various possible moves gains control over an ...
overactor's user avatar
  • 654
11 votes
1 answer
336 views

Binary Tree/ Amorphous Binary Tree Creator

I suppose this is a two-part question. The first part is just a simple implementation of a Binary Tree (BTree), with pre-order, post-order, and in-order searches ...
Azar's user avatar
  • 395
1 vote
3 answers
2k views

Lowest common ancestor in recursive tree traversal

LCA = Lowest Common Ancestor The following code finds the lowest common ancestor in tree of nodes, where a node can have two parents, left and right. The tree looks like this: ...
NimChimpsky's user avatar

15 30 50 per page