A string is a sequence of characters. It is commonly used to represent text or a sequence of bytes. Use this tag along with the appropriate programming language being used.
2
votes
1answer
40 views
Counting all substrings with exactly k distinct characters
Problem Statement : Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that has exactly k distinct characters. Example:
Input: abc, k = 2 Output: 2 ...
2
votes
3answers
45 views
Optimizing Java SHA-512 String-to-Hash Generator
In an attempt to learn Java and SHA-2 I created a very simple String-to-SHA512 generator. Here is the code:
...
3
votes
3answers
50 views
Acronym Generation
Problem
Implement a relatively naive acronym generation. I was trying to implement a solution without using regex.
Portable Network Graphics => ...
-1
votes
0answers
17 views
7
votes
1answer
84 views
Cipher text using a 2D array
I have a simple program which ciphers text using a 2D array. You specify what letters to replace with what and it does it.
I understand the code is very repetitive and that I should probably use ...
6
votes
3answers
74 views
Table printing code using a fluent interface
Let's say you want to display something like:
One Two Three Four
1 2 3 4
And since you hate the idea of predefining the widths of the columns you ...
3
votes
1answer
39 views
Finding the Nth occurrence of character in string
I wrote an SQL Server function which returns the substring before the Nth occurrence of a character.
For example:
...
1
vote
1answer
31 views
Building a query URL in Scala
I'm working on a webapp in ScalaJS and want to create a query url for requesting some JSON.
Right now I'm using a method called urlBuilder to take the query options from an Options case class and ...
9
votes
1answer
421 views
Palindrome-inize a number
For example if I start with the number 146. I first reverse it, so it becomes 641. Then I add this to the original number to ...
10
votes
1answer
140 views
Implementing a string class in C++
I recently attended an interview for a C++ position in a very reputed bank.
The interviewer started off by asking me to implement a string class but was only interested in constructor, copy-...
7
votes
5answers
1k views
Interview solutions to reverse a string and reverse a sentence
Recently in an interview I was asked to
Write a method to reverse a string. I used StringBuilder but was asked not to use reverse method of builder but iterate ...
2
votes
1answer
42 views
Processing a string containing product variants
I have a variable containing a string in this format "Size-XS|Size-XL|Color-Red|Color-Green". When i process it the final result is "Variations: Size: XS, XL, Color: Green, Red. The code for this is ...
5
votes
2answers
51 views
Finding longest common prefix
I have been trying to solve a modification of the Longest Common Prefix problem. It is defined below.
Defining substring
For a string P with characters P1, P2,…, Pq, let us denote by P[i, j]
...
1
vote
1answer
115 views
Function to find a substring within a string [closed]
I've just completed an exercise in which I had to create a program that searches for a string within another bigger string.
If the substring exists then it is outputted to confirm and the starting ...
1
vote
1answer
40 views
Concatenating an array of optional NSAttributedStrings
Imagine you had to join together attributed strings with a separator in between them. Which of the following methods would you use?
An extension on SequenceType with a function that takes in a ...
9
votes
2answers
451 views
Break a full name into a dictionary of its parts
It seems like I'm repeating myself here. Is there a standard way to deal with code like this?
...
3
votes
2answers
921 views
Morse Code Conversion
Challenge
Write a program which reads a file containing Morse Code and outputs the conversion.
Specifications
The first argument is a path to a file.
The file contains multiple lines.
Each line ...
2
votes
1answer
67 views
Concatenating two substrings to provide the largest possible palindromic string
The code extracts two substrings from different strings and concatinating them to provide the largest possible palindromic string.
Objective:
You have two strings, (a) and (b). Find a string, (c),...
10
votes
2answers
187 views
Displaying all substrings of some given string
I solved exercise 8 from Core Java for Impatient, chapter 1. This exercise is to implement a displayAllCombinations method to display all substrings of the given ...
3
votes
2answers
37 views
Getting the smallest snippet from content containing all keywords
This returns the smallest snippet from the content containing all of the given keywords (in any order). This provides the correct solution but I would like to know if it can be made more efficient.
<...
1
vote
1answer
53 views
Java password encryption based on time and string
I have a program that:
Takes a user specified string
Creates password from the string and previous, current, and next day
Encrypts the strings
Chops some middle characters from the strings (needed ...
8
votes
3answers
893 views
Word-counting script in C#
My goal is to read from standard input, break up the input into words (Unicode letters and apostrophes), case-insensitively, and produce a report to standard output, where each line is a word followed ...
3
votes
1answer
36 views
Matlab implementation of Needleman-Wunsch algorithm
This code (an implementation of the path finding Needleman-Wunsch algorithm), given two sequences, correctly aligns and calculates the similarity of them. For example, given two sequences:
AAA,CCC
...
10
votes
2answers
226 views
Converting Morse Code
Challenge
Write a program which reads a file containing Morse Code and outputs the conversion.
Specifications
The first argument is a path to a file.
The file contains multiple lines.
Each line ...
1
vote
1answer
69 views
Check if vector of strings has matching brackets
For an online screen, I had a question that would take in a vector of strings, and return a vector of strings indicating whether the input string was a valid combination of ...
4
votes
3answers
101 views
Program to reverse a string using std::string
Background: I'm trying to learn C++ and I'm doing that by writing some programs by myself. I'm decent with C, but I'm having trouble translating to OOP paradigm. I'm reading from learncpp.com and a ...
4
votes
0answers
27 views
Princeton KMP implementation
I implemented a Python version of KMP followed by Princeton Prof Robert Sedgewick's discussion.
However, I got a Time Limit Exceeds error. Per leetcode's explanation, TLE indicates that the solution ...
3
votes
2answers
74 views
Finding the index of the character whose removal will make a palindrome
Before I get into describing by problem I'd like to point out I found this question under c++ tag. But the solution of that question is already implemented in my ...
5
votes
2answers
45 views
Analyze huge set of sentences for word presence
I have a huge file (1Gb) with English sentences and I need to filter only those containing the Alice word.
Actual tests could be more complex, e.g. matching a verb by its wordforms (go, goes, gone, ...
51
votes
1answer
4k views
NUMAH LITTERS OV KITTEHS ON TEH NETZ
It's not fair that 1% of the users hold 75% of the lolcode questions. #OccupyMatsMug
~ user2296177
I agree. Without further ado, here's the LOLCODE version of 99 bottles of beer on the wall:
<...
0
votes
1answer
32 views
2
votes
2answers
83 views
Implementing a Sort for an Array
Yesterday, I gave an interview after a long time, and I was asked a question which I couldn't solve on the spot.
I had to implement a sort function for a Array of strings in JavaScript, with the ...
4
votes
1answer
197 views
Checking if two strings are anagrams
Here is my code for checking to see if two strings are anagrams. This seems a little short. Am I missing anything? Both time and space complexity seem to be \$O(1)\$.
...
1
vote
1answer
37 views
Log collisions in generating unique random strings
I've created a small class to generate unique random strings. It works fine. I also want to log the collisions of the generated strings. I check if the generated string is in the array for uniquness:
...
3
votes
2answers
90 views
'Broken Record' Coding Challenge
I was asked to complete a coding challenge for an interview. The challenge being to write a test function to check whether or not a string was a broken record. A <...
7
votes
3answers
372 views
Converting string to control
This is my first post here. I had a look for my question, but nothing quite answered what I'm looking for. I've just started learning C#.
I have an up-down numeric control on my form (...
28
votes
8answers
6k views
C program that reverses a string
As practice with the (ever so painful) C Strings I wrote a string reversal program. I am new to C, so I wanted to make sure that I am not using bad coding practices. It runs just fine (at least with ...
0
votes
2answers
80 views
Checking if a string has all unique characters
I'm wondering if this code can be optimized in terms of time complexity. The problem is checking to see if a string has all unique characters.
...
0
votes
0answers
36 views
Suffix tree code
I am always having confusion when it comes to run time complexity of an algorithm. I wrote this code for suffix array, I am not sure of the run time complexity of ...
6
votes
4answers
971 views
Implement an algorithm to determine if a string has all unique characters
I'm working through Cracking the Coding Interview. The first challenge is to implement an algorithm to determine if a string has all unique characters.
I've gone through several iterations, but here'...
1
vote
1answer
66 views
Removing a specific character and its neighbors from a string
Assume we have an string that contains the character 'c'. This character can be located anywhere within the string. The exercise ...
1
vote
1answer
44 views
3
votes
1answer
49 views
Count character replacements needed to make string a palindrome
Problem
Count the number of character replacements necessary to convert an input String to a palindrome.
Each character replacement must replace the given ...
6
votes
2answers
79 views
Find the longest string without repeating a letter
I've written some code to scan large files and search for long strings that you can write without repeating a letter. I'm self-taught in python and I'm wondering what I've missed.
...
0
votes
2answers
70 views
5
votes
1answer
139 views
Broken keyboard challenge
Inspired by Reddit r/dailyprogrammer
Help! My keyboard is broken, only a few keys work any more. If I tell you what keys work, can you tell me what words I can write?
The program works fine, ...
1
vote
1answer
42 views
Printing the power set of a given set of elements
Input: Set of elements (String)
Output: Printing the elements of the power set of the given set
...
2
votes
2answers
123 views
Reverse string in JavaScript without using reverse()
I have to reverse a string in JavaScript and cannot use the built in reverse() function. It does not seem efficient to have to create two arrays but is there a ...
1
vote
2answers
55 views
Finding a word with the most occurrences of a character
I am new to PHP development. So Kindly, review my code and guide me make it better/optimize. Currently, it works well with inputs that I have tried.
...
3
votes
4answers
131 views
Remove adjacent duplicate characters
Introduction
This problem is essentially equivalent to this HackerRank problem.
The task is to remove all duplicate characters that are adjacent to each other in a given ...