String interning riddle

I am struggling with the following riddle of my coworker: public class App1 { public static void main(String[] args) { String s1 = "Ja".concat("va"); // seems to be interned?! String s2 = s1.intern(); System.out.println(s1 == s2); // ...
more »

2017-09-16 22:09 (6) Answers

Seg fault on binary search tree - big sorting

Trying to do this Big Sorting problem on Hackerrank. I know there are simpler ways to write the algorithm, but I am trying to brush up on my C knowledge, and as such wanted to challenge myself and write a Binary Search Tree for the problem. The bina...
more »

2017-09-16 20:09 (2) Answers

return C++ local string to another function

Here is my confusion. I think s1 and s2 are function local object instance of type string, we should not return function local scope object to outside. But it seems below code works, wondering why? vector<string> testString(){ vector<st...
more »

2017-09-16 06:09 (3) Answers

Adding to an existing String Value

So in a document I wish to convert a column of letters into a single cell. For example if the column contained the letters h,e,l,l,o then the program would put into a single cell "hello". I attempted to do this with the following code but it leaves t...
more »

2017-09-15 18:09 (2) Answers

Removing Text from Part of String

I am needing to remove text within different strings. I need a function that will make the following... test: example1 preview: sample2 sneakpeak: model3 view: case4 ...look like this: example1 sample2 model3 case4 I have tried using the subst...
more »

2017-09-15 17:09 (4) Answers

Sort list of string based on length

I have a list of strings List("cbda","xyz","jlki","badce") I want to sort the strings in such a way that the odd length strings are sorted in descending order and even length strings are sorted in ascending order List("abcd","zyx","ijkl","edcba")...
more »

2017-09-14 08:09 (2) Answers

Writing to input and output files in c++

I cannot get my code to compile because it keeps telling me "error: no matching function for call" on line 16. Any advice? I am suppose to read the file and write all the vowels to an output file. #include <iostream> #include <fstream> #...
more »

2017-09-13 07:09 (1) Answers

Sort dataframe by length of a string column

Using Python. I have a dataframe with three columns: Author | Title | Reviews I want to sort by the length of the string in the Reviews column. If I do df.sort_values('Review', ascending = False) It sorts alphabetically, starting with 'z'. ...
more »

2017-09-12 15:09 (2) Answers

Sort List of strings aternately

So basically I have a list of strings say : ['cbad','hfig','qspr','uyxz'] I want to sort these strings in an alternate fashion without changing their relative position : ['abcd' ,'ihgf', 'pqrs', 'zyxu'] i.e. 'abcd' is sorted in ascending order,...
more »

2017-09-12 05:09 (1) Answers

Swift string and integer subscripts

This is rather a theoretical question why the following (and more in analogy) is not a part of the Swift standard library? What would be bad cases? extension String { subscript(_ range: Range<Int>) -> Substring { return self[in...
more »

2017-09-11 21:09 (1) Answers

Impala: convert dd-MMM-yy string to yyyy-mm-dd

I'm receiving a csv with dates in a dd-MMM-yy format, e.g. 29-aug-17 I want to convert them into yyyy-MM-dd, e.g. 2017-08-29 It could be just me not having googled the correct function, but I can't find anything to cope with the MMM way ...
more »

2017-09-11 17:09 (2) Answers

Write to a file using fputs in C

Could someone tell me why the file doesn't change? It works when I use rewind or fseek but not otherwise. What's the standard way of using fputs after fgets. The file indicator is at position 9 so fputs must write after that, but it doesn't do anyth...
more »

2017-09-11 11:09 (2) Answers

Yes no string in C

I've searched the forums, and I can't seem to find an answer that is suitable for my specific problem (I tried Google as well). I seem to be having an issue comparing the strings ("Yes", "yes", "No", "no") correctly. I tried an if else originally, ...
more »

2017-09-10 23:09 (2) Answers

Equal strings produces different hash index

I have a program here that does replicate a memory filesystem (not finished yet), it has to read from a file its commands and they are pretty self explanatory here: create /foo create /foo/bar create /foo/baz create /foo/baz/qux write /foo/bar "tes...
more »

2017-09-09 13:09 (1) Answers

Convert numbers in substring to words in java

I'm novice to java. I want to convert numbers in substring to English words with certain position in a string. For example, the string ABC12345DEFG and substring(3,8) should output the following. ABConetwothreefourfiveDEF I tried with the followi...
more »

2017-09-08 05:09 (5) Answers

r programming: align two sequences of words

I want to align two datasets that mostly intersect on one column -- but each dataset is missing some rows. For example: df1 <- data.frame(word = c("my", "dog", "ran", "with", "your", "dog"), freq = c(5, 2, 2, 6, 5, 10)) df2 <...
more »

2017-09-08 02:09 (1) Answers