Skip to content

ThoughtWorks split wise (code pairing or machine coding round) assignment revised version

Notifications You must be signed in to change notification settings

pulkitent/thoughtworks-split-wise-assignment-revised

Repository files navigation

PROBLEM STATEMENT

A group of friends go out for an outing to explore Chennai. On the trip, they incur various expenses like bus tickets, taxi fare, museum tickets and food etc. One of them paid for taxi while other one paid for the evening snacks. Similarly, different expenses were paid by them in a random manner. Also, for some expenses, only few people are part of it.

Now they need need an application that can tell how much a person owes and how much he needs to give.

Sample Input : (you can keep this sample input in your code/file - ie no need for user input, but you should not hardcode the number of friends in the group) ———————— A spent 100 for Snacks for A, B, C, D. B spent 500 for Taxi for C, D. D spent 300 for Bus for A, B.

Sample output:

A gives 75, B gets 325, C gives 275, D gets 25

Extensions: •Find the person to person transactions: C needs to pay 275 to B, A needs to pay 50 to B, A needs to pay 25 to D •Introduce weightage (uneven split). For an expense of 100, Person A incurs 75 and Person B incurs 25. For eg. {A: 0.1}, {B: 0.2}, {C: 0.7}

PS - trunk based development was followed as was hosting this project on gitlab with proper CI/CD but in the end migrated here on Github, Hence only master branch

What the company is looking for or what are the company's expectations?

They are looking for people who can write code that has flexibility built-in, by adhering to the principles of Object-Oriented Development, and have the ability to deal with the real-life constraints/trade-offs while designing a system.

It is important to note that they are not looking for a GUI and they are not assessing you on the capabilities around code required to do the I/O. The focus is on the overall design. So, while building a solution, it would be nicer (not mandatory) if the input to the code is provided either via unit tests or a file. Using a command-line (for input) can be tedious and difficult to test, so it is best avoided (again not mandatory). Following is a list of things to keep in mind, before you submit your code for any LLD/OOD/OOPs round:

  1. Clear identification of domain entities or classes and their relations with appropriate object modeling using composition.

  2. Functionality should not be dumped in a single class, method, or file (don't create God class).

  3. Write a clean Code with clear intention so as to have good readability (Proper Naming Conventions, Self-documenting code, Avoid redundant commenting, etc).

  4. Clear and logical separation of responsibilities with proper boundaries (emphasis on single responsibility (SRP) for high cohesion).

  5. Have you applied the principles of YAGNI and KISS?

  6. Have you applied SOLID principles to your code?

  7. Is the behavior of an object distinguished from its state and is the state encapsulated?

  8. Have you looked at basic refactoring to improve the design of your code?

  9. Are the principles applied in a pragmatic way.

  10. Code should be easily extensible & maintainable

  11. Atomicity and Coverage of Unit Tests.

Simplicity is the strongest trait of a piece of code. However, easily written code may not necessarily be simple code.

Why LLD/OOD/OOPs in software engineering interviews?

So main reason behind asking this kind of problems in an interview is to see whether a candidate can do the following:

  1. Can a candidate write a working code in a given short span of time? So as to measure his/her delivery capability?

  2. Can a candidate write highly readable, maintainable & extensible code? The intention must be clear by reading the code (Check 4 rules of simple design)

  3. Can a candidate follow the principle of DRY (Don't Repeat Yourself) and avoid breaking encapsulation by following or Fat model pattern or Domain-Driven Design(DDD)? (Read tell don't ask principle and Law Demeter)

  4. Can a candidate achieve the solution with a minimum number of elements using the YAGNI principle (that is without creating unnecessary interfaces etc)?

Rules they want you to follow:

You should not use any external libraries to solve this problem, but you can use external libraries or tools for building or testing purposes. Specifically, you can use unit-testing libraries or build tools available for your chosen language (e.g., JUnit, Ant, NUnit, Rspec, Rake, etc.).

They assess a number of things including the design aspect of your solution and your object-oriented programming skills. While these are small problems, They expect you to submit what you believe is production-quality code; code that you’d be able to run, maintain and evolve. You don’t need to gold plate your solution, however, we are looking for something more than a bare-bones algorithm.

Things I tried to follow in this project/repo:

  1. Tried to create all the required domain entities/models as per the problem statement.

  2. Tried not to break encapsulation by avoiding getters & setters (as much as possible).

  3. Tried to have an immutable state with value objects (as much as possible) so as to avoid concurrency issues (Thread safety).

  4. Tried to have readable methods & variables naming so as to clear the intention (4 rules of simple design).

  5. Tried to have small & logical commits.

  6. Tried to avoid code duplication by refactoring/reusing duplicate code (DRY).

  7. Didn't make interfaces as per YAGNI principles because for now, I don't feel the need for the same (Yes, I am aware of this principle also - "Program to interfaces rather than concrete implementation").

  8. Tried to put some comments so as to make business logic more understandable.

  9. Wrote the job on every class so as to clear its use case.

Things I could have done/improved in this project/repo if given more time :

  1. TDD with 100% code coverage.

  2. Code duplication can be further reduced to some extent.

  3. Level of indentation can be further reduced in some methods by breaking them into smaller methods.

  4. Encapsulation of behavior in some classes can be further improved.

  5. More mocking and stubbing of test data in unit tests.

About

ThoughtWorks split wise (code pairing or machine coding round) assignment revised version

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages