Posts Tagged ‘tech’

Finding longest palindrome in a string

Posted by guptaradhesh on August 26, 2013

Here is an elegant code I found.

string expandAroundCenter(string s, int c1, int c2) {

  int l = c1, r = c2;
  int n = s.length();
  while (l >= 0 && r <= n-1 && s[l] == s[r]) {
  return s.substr(l+1, r-l-1);
string longestPalindromeSimple(string s) {
  int n = s.length();
  if (n == 0) return “”;
  string longest = s.substr(0, 1);  // a single char itself is a palindrome
  for (int i = 0; i < n-1; i++) {
    string p1 = expandAroundCenter(s, i, i);
    if (p1.length() > longest.length())
      longest = p1;
    string p2 = expandAroundCenter(s, i, i+1);
    if (p2.length() > longest.length())
      longest = p2;
  return longest;
source: here

Posted in java, puzzles/ algorithms, tech | Tagged: , , , | Leave a Comment »

Why char array is preferred over String for storing password?

Posted by guptaradhesh on August 23, 2013

String is immutable in java and stored in String pool. Once it’s created it stays in the pool until unless garbage collected, so even though we are done with password it’s available in memory for longer duration and there is no way to avoid it. It’s a security risk because anyone having access to memory dump can find the password as clear text.

If we use char array to store password, we can set it to blank once we are done with it. So we can control for how long it’s available in memory that avoids the security threat with String.

Posted in java, tech | Tagged: , , , | Leave a Comment »

Some Interview puzzles by Apple

Posted by guptaradhesh on April 18, 2013


Posted in puzzles/ algorithms, tech | Tagged: , , , | Leave a Comment »

Startup & Tech Events happening around

Posted by guptaradhesh on June 26, 2012

I wonder how come I didn’t know about this. Being always interested in Startup Tech related events happening around – I keep myself updated on meetupeventbitetechcrunchlinkedIn,facebook, few mailing-lists and with some of my friends. I just happened to stumble on GARYSGUIDE. It looks quite impressive and is definitely something I would bookmark and keep a track of.

To know about Startup and Tech events happening around, checkout: http://www.garysguide.com/

Posted in markets | Tagged: , , , , , , , , | Leave a Comment »