Posts

Showing posts with the label Code Tips

Integrating Code Syntax on a Blog or Website.

Image
As a developer, one is used to seeing code snippets formatted in a specific way. Eg: public class FormatCodeClass{ { public void showFormattedMethod() { System.out.println("Yay"); } } Fortunately, most websites that support these snippets use some kind of library that can be used to render this easily. The one that I use on my blog is called Google Pretty Print. I'll be explaining how to integrate this into your website/Blogger.  Step 1) Add the library to your HTML above the <body> tag Click on Themes, then on Edit HTML. Search for the <body> tag and copy  <script src='https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js'/> above it.  Step 2) Add in your preferred CSS above the </head> tag <!--Desert theme--> <style type='text/css'>pre .atn,pre .kwd,pre .tag{font-weight:700}pre.prettyprint{display:block;background-color:#333}pre .nocode{background-color:none;color:...

Cup of Java #1 - Odd One Out

Image
Welcome to my Cup of Java series, where I'd like to tackle some fun coding challenges/questions and also dive into interesting Java related material. "White board" questions are quite common in technical interviews. As one can imagine, the pressure to perform while under the spotlight can be overwhelming. Back in 2012, I was asked my first white board question during a technical interview.  The question went as follows: "Given an array of integers N, write a method that will return the integer that is repeated an odd number of times. E.g: In the array [1, 1, 6, 2, 1, 6, 2, 1, 2], the odd integer is 2. Note that there will be only one of these integers. The order of the numbers are random." My first attempt to solve the solution used multiple temporary arrays. The solution worked, but was inefficient, possibly O(n squared). My interviewers asked that if I was given more time, how would I improve on my answer. The below was second attempt whi...