Add Digits

Title: Add Digits Source: leetcode.com Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. Follow up: Could you do ...

Bulls and Cows

Title: Bulls and Cows Source: leetcode.com You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that indicates how many digits in said guess match your secret ...

Find maximal uni-directional path length for a Binary Tree 1

Continuing from our last post for a Generic Binary Tree implementation, we’ve come up with a solution to quite an interesting problem. We define a path in a binary tree to be a non-empty sequence of nodes that one can traverse by following the pointers in the nodes. A path only goes to the right ...

Implementing a Generic Binary Tree in Java 2

Implementing a Generic Binary Tree in Java
The following two classes demonstrate an implementation of the Generic Binary Tree data structure. The first class is BinaryTreeNode.java which acts as the node class for the tree, holding integer type data and two pointers for left and right child respectively of type same as the node class itself. The member fields are declared to ...

Data truncation: Incorrect datetime value: ” for column 2

While using Acitiviti API you might encounter this error which says something like this ### Error updating database. Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: ” for column ‘DEPLOY_TIME_’ at row 1### The error may involve org.activiti.engine.impl.persistence.entity.DeploymentEntity.insertDeployment-Inline### The error occurred while setting parameters### Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: ” for column ‘DEPLOY_TIME_’ at row ...

Python newline caveat

Hello Everyone, This will be a small post about a caveat in Python language (v2.7) for writing output to files. On Windows the new line character is actually treated as ‘\r\n‘ or CRLF as we know it (Carriage Return followed by a Newline). Sometimes however you may not want to output this newline character into ...

Structure vs Union in C – Coded Approach

Hello Everyone, Today we are going to talk a bit about the difference between structure and union as in C programming language. We are going to provide a coded approach so that you could see the difference practically as the theoretic differences you can read from anywhere on the internet and your text books. Here ...

Add Two Integers without using Arithmetic Operators

Recently came across an interesting question of adding two numbers without using any of the arithmetic operators and thought of giving it a try. The first thought of solving the question was using bit-manipulation operations. The idea was to add the numbers bit-by-bit taking any carry forward (without actually adding them and instead using bit-wise ...

Lexicographically Bigger String

The following piece of code accepts as input a single string of characters and produces on standard output a string which would be the next string to appear in lexicographical order. Definition of Lexicographical order : wiki (Also known as The Dictionary order since lexicographical order is one in which the strings would appear in ...

Check if a number is Fibonacci

A Fibonacci number is one which appears in the Fibonacci Sequence. To check if a given number n occurs in the Fibonacci Sequence or not we only need to check if one or both of (5*n^2 + 4) or (5*n^2 – 4) is a perfect square or not (source: wiki). Python code for the same: ...