Conway’s Game of Life Object oriented implementation in Java

I have designed Conway’s Game of Life in Java, the solution follows Object Oriented design and paradigm, please review and let me know the feedback Class Cell Cell has one property alive and behavior to update alive status public class Cell { private boolean alive; public Cell( boolean alive) { this.alive = alive; } public … Read more

Ruby sudoku solver using backtracking (interview)

I was required to implement the code to a spec file I was provided in Ruby. I was rejected with the message “The quality of your code isn’t sufficient for this position”. Can you please tell me what can be improved in order to achieve higher quality? game_board_spec.rb (file provided) require ‘./game’ require ‘./game_board’ describe … Read more

OOP design for waze – coding interview

I took upon myself to try to do a OOP design for Waze, please give a feedback which is OOP design related. Also if you were the interviewer can you think of flow up questions? using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Collections.Generic; using System.Drawing; namespace JobInterviewTests { [TestClass] public class WazeDesign { [TestMethod] public void CarTest() … Read more

Palindrome implementations – iterative and recursive

I got asked this palindrome question when the interviewer wants to make sure that my palindrome can check if “Taco! Cat!” is a palindrome. In this example, my palindromes implementation needs to handle with complex examples, like white space, punctuation and mixed letter casing is_palindrome(‘Taco? Cat.’) returns True. def ascii_letters(text): #Helper method, it return true … Read more

Merge sort Java implementation for an interview

I just learned Merge sort, and I really like this Merge sort implementation since it is very logical and very easy to follow. If I was asked in an interview to implement merge sort, will this implementation suffice? I know creating those new arrays every time the mergeSort() method is called is bad practice. I … Read more

Mark positions attacked by a queen on a chess board

Problem – Given a chess board and the position of only one queen piece in it, mark all the position where the queen can move with X. Kindly review this Scala code and suggest improvements. import scala.collection.mutable._ object ChessQueenAttack { val board = Array.fill(8)(Array.fill(8)(‘0’)) def printBoard = { println println board foreach { row => … Read more

Design a sustainable home tracker and calibrater for power, water, gas to minimize the expense

Problem Statement Following are the various scenarios to be considered Track energy – Track consumption of water, gas and electricity. We should be able extend to capture other type of energies as well (e.g., fuel for vehicles). Apart from storing the consumption and time interval, also look into possibilities of capturing additional attributes for each … Read more

Leetcode – First Unique Character in a String

Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. Examples: s = “leetcode” return 0. s = “loveleetcode”, return 2. Note: You may assume the string contain only lowercase letters. My solution public class FirstUniqueCharacter { public int firstUniqChar(String s) { LinkedHashMap<Character, Integer> map … Read more