-2
votes
0answers
29 views

understand operator precedence [migrated]

Was fixing bug in our code and found this weird function that was misbehaving: ...
6
votes
1answer
109 views

Finding common strings among 2 arrays of strings of length 1, sorted alphabetically in O(n) time complexity

The problem: Start with two arrays of strings, a and b, each in alphabetical order, possibly with duplicates. Return the count of the number of strings which appear in both arrays. ...
2
votes
1answer
28 views

Trie SPOJ Problem - PhoneList TLE

In this problem you are given input of phone numbers and you are supposed to determine whether any number is the prefix of another. I have an addchild method that ...
3
votes
6answers
532 views

Code Hunter 2.06: Count occurrences of 'a' in a string

I'm playing Code Hunt on level 2.06 (loops). This level is about counting the number of "a" in a String. ...
1
vote
2answers
62 views

Given suffix array and a pattern, search if given pattern exists

Given a suffix array for a word, check if a pattern (consecutive chars) exists. Example: A suffix array constructed for "ameya" should return true for "ame" but false for "foo" or false ...
2
votes
1answer
174 views

Read a line from console in Java

I have to read a line of strings and split it for whitespace: ...
0
votes
1answer
92 views

Concat strings in Java

I've written this function that concats strings: ...
7
votes
3answers
315 views

Operations on strings in Java

I have a program that makes operations on strings and this is the principal function of one of those operations. This works perfectly, but it is not efficient: ...
4
votes
1answer
76 views

Wordgenerator algorithm using Java collection

Problem Statement Prompt the user for the order statistic n: 1, 2, 3, etc. Read a file of tokens, building a map ...
3
votes
1answer
45 views

Stripping out all /* */ comments from a paragraph

I've written this code keeping the following cases in mind and I think I've covered them all. I'd really appreciate if someone could help me determine if I've covered all of them. Cases I considered: ...
6
votes
2answers
169 views

How do I better structure Java code to avoid dereferencing null? [closed]

I have the situation where as long as the user gives valid input, the StringBuilder object will not be null. ...
6
votes
3answers
345 views

Find meaningful words from the input string

Given a string find the number of meaningful words which could be formed from the string for eg. programmerit forms: ...
4
votes
3answers
143 views

Changing the foreground and background colors of substrings based on ANSI escape codes

I am checking for particular keywords in a string, and then changing the foreground and background colors of substrings based on the keywords. Following is the snippet for checking the background ...
4
votes
2answers
151 views

Rotating the string optimization

Below is the code for the problem at Codechef. I have made use of the String method .equals in my solution which is working fine ...
3
votes
2answers
189 views

Return the lexicographic order

Given set of words that are lexicographically sorted, return lexicographic order. E.g: abc acd bcc bed bdc dab The order of letters for the given ...
6
votes
2answers
1k views

Count frequency of words in a given file

Write a function that takes two parameters: a String representing a text document an integer providing the number of items to return Implement ...
11
votes
4answers
1k views

What would be preferred aesthetically and performance wise?

Which one of these two would you prefer writing in your code? This: ...
4
votes
1answer
77 views

More efficient way to make a Tweeter status in a string of just words

I am making an application where I will be fetching tweets and storing them in a database. I will have a column for the complete text of the tweet and another where only the words of the tweet will ...
15
votes
7answers
1k views

Why does caching of string objects perform faster?

I'm trying to implement String-Pool. I'm maintaining a HashMap<String,String> to store the keys. ...
8
votes
3answers
376 views

Eliminate duplicates from strings

I have written a piece of code for removing duplicated values from a string. Any suggestions on improvements? ...
10
votes
5answers
838 views

Vertically placing the words in a string

Please let me know a better approach to solve below problem: Problem: Vertically arrange the words in a string and print on console. Sample Input: Hello Jack ...
4
votes
1answer
164 views
9
votes
5answers
1k views

Read and convert binary files to ASCII text

This is my code which receives a file to read and converts binary values to ASCII text. The code works fine, so I am looking for a review on what I have written, and suggestions on how I could do it ...
6
votes
3answers
492 views

Anagram Checking

...
12
votes
7answers
2k views

Check for balanced parentheses

Given an expression string exp, write a program to examine whether the pairs and the orders of "{","}","(",")","[","]" are correct in exp. For ...
10
votes
2answers
71 views

Poke-a-Dot (Provider)

I need to create variable-length strings of dots/periods/full-stops to add to some text content, in a way that is similar to a formatted table-of-contents: ...
5
votes
2answers
62 views

Find and replace String with a substring result

I was asked this recently, and I couldn't figure out the best way. We are trying to replicate Google's search results where the search terms are bolded (using a b tag) in the results. ...
6
votes
1answer
62 views

indexOf() and Boyer Moore methods

I have a method I created which is a custom indexOf(). This code seems ugly to me so I was wondering if anyone could recommend a cleaner and perhaps faster ...
9
votes
2answers
398 views

Converting a numerical string to the equivalent multipled by 100

Method: Input: a string which represents an integer or a non-integer value. Output: a string which represents the same value multiplied by 100. Requirements: No floating-point unless needed. No ...
7
votes
3answers
336 views

Reverse word by word efficiency

I have a method that reverse each word in a string. I want to know how I can increase it's performance and memory efficiency. Ideas I had in mind were simply using ...
5
votes
2answers
1k views

Insert a character into a string

For practicing reasons I would like to write a method which inserts a character into a string. I would like to know: What is the best practice concerning placement of a comment within methods? For ...
1
vote
1answer
133 views

reversing a string test cases

I am trying to create a method that reverses a string that will handle every case. So far the cases I have come up with are "" "abcdef" "abbbba" null I haven't ...
13
votes
4answers
655 views

Count number of each char in a String

I know there is a simpler way of doing this, but I just really can't think of it right now. Can you please help me out? ...
17
votes
5answers
847 views

Custom indexOf() without String methods

I created my own indexOf function. I was wondering if anyone could help me come up with a way to make it more efficient. I am practicing for interviews so the catch ...
8
votes
6answers
5k views

Fast way of searching for a string in a text file

I have written this code to search for a string in a .txt file. Is it possible to optimize the code so that it searches for the string in fastest manner possible? ...
15
votes
4answers
2k views

Reverse a string word by word

Given an input string, reverse the string word by word. For example: Given s = "the sky is blue", return ...
13
votes
5answers
1k views

Reversing the digits of an integer

For CS class, I had to reverse the digits of an integer from the input. This is my solution: ...
13
votes
3answers
3k views

Reverse a String in Java

Here is the code for the CString class that I created. ...
11
votes
3answers
776 views

Customised Java UTF-16

I have implemented customized encoding mechanism for javaUTF16. Does this implementation support all the characters? ...
9
votes
3answers
885 views

Checking brackets nesting in a string

I took a training challenge on Codility that checks for the proper nesting of brackets in a string. The brackets to be checked are {,},(,),[,]. I have written the ...
3
votes
2answers
503 views

Permutation of a string eliminating duplicates

This code lists the permutations of the string, and eliminates duplicates if any. I'm looking for code review, best practices, optimizations etc. Also verifying complexity: O(n! * n) as time ...
1
vote
3answers
3k views

Calculate all possible combinations of given characters

I was asked in my textbook Lectures on Discrete Mathematics for Computer Science to construct a program that would take an alphabet ({a,b,c} or any combination of ...
2
votes
1answer
82 views

Refactor ConvertorToString class

Help me refactor this class that helps to represent an object state as String: ...
5
votes
3answers
2k views

Algorithm to determine if a string is all unique characters

This my solution to one of the practice problems from Cracking the Coding Interview: 150 Programming Interview Questions and Solutions [Book] implement an algorithm to determine of a string has ...
5
votes
2answers
2k views

Finding the most common character in a string

I have started to try and work out the TopCoder problems. The "StringDup" problem asks us to: Create a class called StringDup. Given a string made up of ONLY letters and digits, determine which ...
12
votes
4answers
833 views

Better way to manipulate this string in sequence?

I am working on a small custom Markup script in Java that converts a Markdown/Wiki style markup into HTML. The below works, but as I add more Markup I can see it becoming unwieldy and hard to ...
3
votes
3answers
217 views

Any recommendations to improve this logging framework? Or is it overkill?

So I've been kind of irritated with my logging recently as I find myself copying and pasting the same kinds of generic messages around to lots of different methods or retyping them ever so slightly ...
3
votes
1answer
104 views

Reading and validating 2D matrix bar code

I need a review on this. This code will read a 2D matrix bar code, which I hard-coded as a string str. It has "]d" starting string, which is a GS1 International ...
7
votes
2answers
134 views

Matching program in Java

I am new to Java and wrote one small program. It works fine, but it looks like it doesn't meet OOP concepts. Could someone look and give me advice so that I can fine tune? ...