GithubHelp home page GithubHelp logo

data-to-tree-task's Introduction

data-to-tree-task

data-to-tree-task's People

Contributors

terminusdeus avatar

Watchers

 avatar

data-to-tree-task's Issues

Solution review

Hi, i'm the one who was running the interview; thanks for sending the complete solution, there might have been some pressure during the call - both as it requires coding on a sort of "white board" in the limited time period, and the fact we had to use English - it's really no-go here w/o the language knowledge, the client team members speak fast west coast American English, and some of asian origin have different accents + it's de-facto the only way to communicate here locally till one gets familiar with intermediate level Polish.

There are still few problems with this solution:

  1. A minor one - you sort IDs to pass the smallest one, generally you only need the one where parent_id is zero + sorting to find the minimal element is overkill (N*logN vs. just N to scan)
  2. If you pass some sort of data where a child comes before the parent in the list - which is totally possible if the in-database tree is being edited - you'll find out it doesn't work; try
var input = []Data{
	{1, 0, "str1"},
	{2, 4, "str2"},
	{3, 4, "str3"},
	{4, 1, "str4"},
	{5, 1, "str5"}}
  1. The code complexity is at least O(N**2); a faster O(N) solution, which is also must easier to implement is to create a map[int]*InMemory - indexed by ID with empty children - and then scan this map again adding each scanned element to thatMap[element.ParentID].Children, finally finding the one with ParentID == 0 and returning it.
  2. An extra question is usually - is it possible to create some loop in such an in-database tree and how to make the code detect such sort of loop.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.