shukad333
BAN USER- 1of 1 vote
AnswerYou and your friends are pilots in the Clone army.You are facing the aerial fleet of the Droid army.Droid planes move while maintaining a long line so that their shields interact making it impossible to shoot down planes in the middle of the line.Thus,your only option is to keep shooting down planes at the edges of the line.
- shukad333 in United States
You and your friend have decided to make a game of it.Each Droid plane has an importance level IMP[i].Since the droid planes don't advertise their importance levels, both of you must follow a mixed strategy and shoot down either the first plane or the last plane with 50% chance each.If there is a single plane,the shooter with the turn will shoot it down for sure.The two of you take turns to shoot down enemy planes.You have the first turn.What is the expected sum of importance levels you will shoot down?
Input format:
# The number of droid planes
input1=N(1<=N<=1000)
# An array containing the importance levels of droid planes.
input2=IMP(for 0<i<=N,1<=IMP[i]<=100)
Output format:
A string containing your expected sum of importance levels of shot down planes,rounded to 3 places of decimal.
Example:
Input:
2
10 20
Output:
15.000| Report Duplicate | Flag | PURGE
Capgemini
package com.interviewbit;
import java.util.LinkedList;
import java.util.List;
public class SuffixTrieToSearchInStreams {
public static void main(String[] args) {
SuffixTrieToSearchInStreams suff = new SuffixTrieToSearchInStreams("bananaandotherthingsotherbro");
suff.search("other");
}
SuffixSearchTrie root = new SuffixSearchTrie();
public SuffixTrieToSearchInStreams(String word) {
for(int i=0;i<word.length();i++) {
root.insertSuffix(word.substring(i), i);
}
}
public void search(String word) {
List<Integer> ind = root.search(word);
if(null==ind) {
System.out.println("Pattern not found");
}
else {
for(int i : ind)
System.out.println("Found at "+i);
}
}
}
class SuffixSearchTrie {
SuffixSearchTrie[] children = new SuffixSearchTrie[256];
List<Integer> indexes;
public SuffixSearchTrie() {
indexes = new LinkedList<>();
}
public void insertSuffix(String S , int index) {
indexes.add(index);
if(S.length()>0) {
char first = S.charAt(0);
if(children[first]==null) {
children[first] = new SuffixSearchTrie();
}
children[first].insertSuffix(S.substring(1), index+1);
}
}
public List<Integer> search(String word) {
if(word.length()==0)
return indexes;
if(children[word.charAt(0)]!=null) {
return children[word.charAt(0)].search(word.substring(1));
}
else
return null;
}
}
package com.google;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class WordCount implements Iterable<WordCount> {
String word;
int count;
WordsCountIterator iterator;
public WordCount(List<String> s) {
Iterator<String> it = s.iterator();
iterator = new WordsCountIterator(it);
}
public WordCount() {
}
class WordsCountIterator implements Iterator<WordCount> {
List<WordCount> wordCounts;
int index = 0;
public WordsCountIterator(Iterator<String> iter) {
String prevWord = null, currWord = null;
int prevCount = 1;
while (iter.hasNext()) {
if (null == wordCounts) {
wordCounts = new LinkedList<>();
prevWord = iter.next();
} else {
currWord = iter.next();
if (prevWord.equals(currWord)) {
prevCount++;
} else {
WordCount wc = new WordCount();
wc.count = prevCount;
wc.word = prevWord;
wordCounts.add(wc);
prevWord = currWord;
prevCount = 1;
}
}
}
}
@Override
public boolean hasNext() {
return index < wordCounts.size();
}
@Override
public WordCount next() {
return wordCounts.get(index++);
}
}
public static void main(String[] args) {
String[] input = { "foo", "foo", "foo", "bar", "foo", "bar", "bar" };
List<String> str = new ArrayList<>();
for (int i = 0; i < input.length; i++) {
str.add(input[i]);
}
WordCount wordCount = new WordCount(str);
Iterator<WordCount> wordIterator = wordCount.iterator();
while (wordIterator.hasNext()) {
WordCount word = wordIterator.next();
System.out.println(word.word + " " + word.count);
}
}
@Override
public Iterator<WordCount> iterator() {
return iterator;
}
}
static void DFS(TreeNode node) {
Stack stack = new Stack();
stack.push(node);
while(!stack.isEmpty()) {
while(node.left!=null) {
if(node.left!=null) {
stack.push(node.left);
node = node.left;
}
}
while(true) {
if(stack.isEmpty())
break;
TreeNode n = (TreeNode) stack.pop();
System.out.println(n.data+" ");
if(n.right!=null) {
stack.push(n.right);
n = n.right;
break;
}
}
}
}
package Tree;
public class PathSumToLeaves {
public static void main(String[] args) {
Node n = new Node();
n = n.insertData(1);
n.left = n.insertData(2);
n.right = n.insertData(3);
n.left.left = n.insertData(4);
n.left.right = n.insertData(5);
n.right.left = n.insertData(6);
n.right.right = n.insertData(7);
n.left.left.left = n.insertData(8);
n.left.left.right = n.insertData(9);
sumOfPathNodes(n, 0);
}
static void sumOfPathNodes(Node n ,int prevSum) {
if(n==null)
return;
if(n.left==null && n.right==null)
{
prevSum = prevSum*10 + n.data;
System.out.println(prevSum);
return;
}
else
prevSum = prevSum*10 + n.data;
sumOfPathNodes(n.left, prevSum);
sumOfPathNodes(n.right, prevSum);
}
}
a. Generate all possible permutations using the char sequence .
public static void allPossibleCominations(String prefix , String str) {
int n = str.length();
if(n==0) {
set.add(prefix);
}
else {
// System.out.println(str);
set.add(str);
for(int i=0;i<n;i++) {
allPossibleCominations(prefix+str.charAt(i), str.substring(0,i)+str.substring(i+1,n));
}
}
b. Now , iterate through each word . Consider each character and if the ascii less than the pervious character , disqualify the woed . Else print it
- shukad333 October 26, 2014The code below will remove duplicates from the String array without using extra space in O(n^2) .
1. For each character, check if it is a duplicate of already found characters.
2. Skip duplicate characters and update the non duplicate characters.
package String;
public class RemoveDupciatesInAString {
public static void main(String[] args) {
String s = "Shuhail";
// char[] s = "{'s','h'm";
char[] st = {'s','h','u','h','a','s'};
removeDuplicates(st);
for(char t : st)
System.out.print(t);
// System.out.println(s);
}
public static void removeDuplicates(char[] str) {
if (str == null) return;
int len = str.length;
if (len < 2) return;
int tail = 1;
for (int i = 1; i < len; ++i) {
int j;
for (j = 0; j < tail; ++j) {
if (str[i] == str[j]) break;
}
if (j == tail) {
str[tail] = str[i];
++tail;
}
}
str[tail] = 0;
}
}
Heartbleed is basically a bug that was concerned with the usage of openssl . In brief , its - missing bounds check in the handling of the TLS heartbeat extension can be
used to reveal up to 64k of memory to a connected client or server...
http://support.novell.com/security/cve/CVE-2014-0160.html
import java.util.HashMap;
import java.util.Map;
public class TwoIntgerThatSumToAGivenNumber {
public static void main(String[] args) {
int[] array = new int[]{2,3,5,7,8,10};
printPairs(array, 10);
}
static void printPairs(int[] arr , int sum) {
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for(int i : arr)
map.put(i, 0);
for(int i=0;i<arr.length;i++) {
if(map.containsKey(sum-arr[i])) {
System.out.println(arr[i]+"+"+(sum-arr[i])+"="+sum);
}
}
}
}
public class DiagonalFormat {
public static void main(String[] args) {
int[] arr = {1,2,3,4,5,6,7,8};
int start = 0;
int inc = 1;
for(int i=0;i<arr.length;i++) {
printDiagonal(arr,start, inc);
inc = inc+1;
start += inc;
System.out.println();
}
}
static void printDiagonal(int[] arr , int start , int inc) {
for(int i=start;i<arr.length;i++) {
if(start>=arr.length)
return;
System.out.print(arr[start]);
start += inc;
inc++;
}
}
}
public class FlipZero {
public static void main(String[] args) {
//System.out.println(countMax("10011101111"));
System.out.println(getFlipIndex("10111101101011101"));
}
static int getFlipIndex(String inp) {
int len = inp.length();
int max = 0;
int index = 0;
for(int i=0;i<len;i++) {
if(inp.charAt(i) == '0'){
int localMax = countMax(inp.substring(0, i)+"1"+inp.substring(i,len));
if(localMax > max) {
max = localMax;
index = i;
}
}
}
return index+1;
}
static int countMax(String inp) {
if(inp==null || inp.isEmpty())
return -1;
int len = inp.length();
int count = 0;
for(int i=0;i<len;i++) {
if(inp.charAt(i)=='1') {
int localCount = 1;
for(int j=i+1;j<len;j++) {
if(inp.charAt(j)=='1')
localCount++;
else
break;
}
if(localCount>count)
count = localCount;
}
}
return count;
}
}
import java.util.ArrayList;
import java.util.List;
public class SplitWithoutFunction {
public static void main(String[] args) {
String test = "Shuhail Kadavath Abc";
String[] st = split(test, " ");
for(String s : st)
System.out.println(s);
}
public static String[] split(String s,String pat) {
List<String> str = new ArrayList<>();
int st=0;
for(int i=0;i<s.length();i++) {
if((""+s.charAt(i)).equals(pat)) {
str.add(s.substring(st,i));
st=i+1;
}
}
if(st<s.length())
str.add(s.substring(st,s.length()));
String[] op = new String[str.size()];
return (String[]) str.toArray(op);
}
}
package tree;
public class BalancedTreeFromSortedArray {
public static void main(String[] args) {
int[] arr = { 1,2,3,4};
TreeBST tree = arrayToBST(arr, 0, arr.length-1);
preorder(tree);
}
static void preorder(TreeBST root) {
if(root!=null) {
System.out.println(root.data+" ");
preorder(root.left);
preorder(root.right);
}
}
static TreeBST arrayToBST(int[] arr , int start , int end ) {
if(start>end)
return null;
int mid = (start+end)/2;
TreeBST root = new TreeBST();
root = root.TreeBST(arr[mid]);
root.left = arrayToBST(arr, start, mid-1);
root.right = arrayToBST(arr, mid+1, end);
return root;
}
}
class TreeBST {
TreeBST left;
TreeBST right;
int data;
public TreeBST TreeBST(int data) {
TreeBST tree = new TreeBST();
tree.left = null;
tree.right = null;
tree.data = data;
return tree;
}
}
package string;
import java.util.HashSet;
import java.util.Set;
public class AllPossiblePermutations {
static Set<String> set = new HashSet<String>();
public static void allPossibleCominations(String prefix , String str) {
int n = str.length();
if(n==0) {
set.add(prefix);
}
else {
// System.out.println(str);
set.add(str);
for(int i=0;i<n;i++) {
allPossibleCominations(prefix+str.charAt(i), str.substring(0,i)+str.substring(i+1,n));
}
}
}
public static void main(String[] args) {
allPossibleCominations("", "12 ");
for(String s : set) {
System.out.println(s);
}
}
}
public class IsTreeBST {
public static void main(String[] args) {
NodeIsTreeBST temp = new NodeIsTreeBST();
temp = temp.NodeIsTreeBST(6);
temp.left = temp.NodeIsTreeBST(5);
temp.left.left = temp.NodeIsTreeBST(3);
temp.left.left.right = temp.NodeIsTreeBST(20);
temp.right = temp.NodeIsTreeBST(33);
temp.right.left = temp.NodeIsTreeBST(20);
temp.right.right = temp.NodeIsTreeBST(50);
System.out.println(isBST(temp, Integer.MIN_VALUE, Integer.MAX_VALUE));
}
public static boolean isBST(NodeIsTreeBST node , int min , int max) {
if(node == null)
return true;
if(node.data < min || node.data>max)
return false;
if(!isBST(node.left, min, node.data-1) || !isBST(node.right, node.data+1, max))
return false;
return true;
}
}
class NodeIsTreeBST {
int data;
NodeIsTreeBST left;
NodeIsTreeBST right;
public NodeIsTreeBST NodeIsTreeBST(int data) {
NodeIsTreeBST temp = new NodeIsTreeBST();
temp.data = data;
temp.left = null;
temp.right = null;
return temp;
}
}
import java.util.ArrayList;
import java.util.List;
public class TriangleConstruction {
public static void main(String[] args) {
int[] arr = {4,7,3,6,7};
List<int[]> op = constructArray(arr);
for(int i=op.size()-1;i>=0;i--) {
int[] temp = op.get(i);
for(Integer in : temp) {
System.out.print(in+" ");
}
System.out.println();
}
}
static List<int[]> constructArray(int[] arr) {
int len = arr.length;
List<int[]> op = new ArrayList<int[]>();
while(true) {
int ctr = --len;
if(ctr==0)
break;
int[] temp = new int[ctr];
for(int j=0;j<ctr;j++) {
temp[j] = arr[j] + arr[j+1];
}
op.add(temp);
arr = temp;
}
return op;
}
}
T = int(input())
t = 1
MAX_LEVEL = 400
next_level = [0]
for i in range(1, MAX_LEVEL): # level 1 to 400 - 1
for j in range(i):
next_level += [i]
MAX_CUPS = MAX_LEVEL * (MAX_LEVEL+1) // 2
while t <= T:
print("Case #"+str(t)+": ", end="")
t+=1
lines = input().split()
b = int(lines[0])
l = int(lines[1])
n = int(lines[2])
level = 1
cups = [[0 for i in range(MAX_CUPS+1)] for j in range(l+2)]
cups[1][1] = 750 * b
while level <= l:
# print(" level", level)
# print(level * (level + 1) // 2 + 1)
for i in range(1, level * (level + 1) // 2 + 1):
# print(i)
if cups[level][i] > 250:
rem = cups[level][i] - 250
# print(" rem", rem)
cups[level][i] = 250
cups[level+1][i] += rem / 3
cups[level+1][i + next_level[i]] += rem / 3
cups[level+1][i + next_level[i]+1] += rem / 3
level += 1
# print(cups[3])
print(cups[l][n])
static void printSmallest(int[] arr) {
int len = arr.length;
int stIndex = -1;
int endIndex = -1;
int max = Integer.MIN_VALUE;
for(int i=0;i<len-1;i++) {
/*
if(arr[i]>max){
stIndex = i;
j
}
*/
if(arr[i]>arr[i+1]) {
stIndex = i;
break;
}
}
for(int i=len-1;i>0;i--) {
if(arr[i]<arr[i-1]) {
endIndex = i;
break;
}
}
int min = minIndex(Arrays.copyOfRange(arr, stIndex, endIndex+1));
max = maxIndex(Arrays.copyOfRange(arr, stIndex , endIndex+1));
for(int i=0;i<stIndex;i++) {
if(arr[i]>min)
stIndex = i;
}
for(int i=len-1;i>=endIndex+1;i--) {
if(arr[i]<min)
endIndex = i;
}
for(int i=stIndex;i<=endIndex;i++)
System.out.print(arr[i]+" ");
}
static int minIndex(int[] arr) {
int min = Integer.MAX_VALUE;
for(int ele : arr) {
if(ele<min)
min = ele;
}
return min;
}
static int maxIndex(int[] arr) {
int max = Integer.MIN_VALUE;
for(int ele : arr) {
if(ele>max)
max = ele;
}
return max;
}
import java.util.Arrays;
public class MouseHole {
public static void main(String[] args) {
int[] Mouse = {4,-4,2};
int[] Hole = {4,0,5};
getMax(Hole,Mouse);
}
static void getMax(int[] Hole , int[] Mouse) {
Arrays.sort(Hole);
Arrays.sort(Mouse);
int max = Integer.MIN_VALUE;
for(int i=0;i<Hole.length;i++) {
max = Math.max(Math.abs(Hole[i]-Mouse[i]), max);
}
System.out.println(max);
}
}
public class IsTreeBST {
public static void main(String[] args) {
NodeIsTreeBST temp = new NodeIsTreeBST();
temp = temp.NodeIsTreeBST(6);
temp.left = temp.NodeIsTreeBST(5);
temp.left.left = temp.NodeIsTreeBST(3);
temp.left.left.right = temp.NodeIsTreeBST(20);
temp.right = temp.NodeIsTreeBST(33);
temp.right.left = temp.NodeIsTreeBST(20);
temp.right.right = temp.NodeIsTreeBST(50);
System.out.println(isBST(temp, Integer.MIN_VALUE, Integer.MAX_VALUE));
}
public static boolean isBST(NodeIsTreeBST node , int min , int max) {
if(node == null)
return true;
if(node.data < min || node.data>max)
return false;
if(!isBST(node.left, min, node.data-1) || !isBST(node.right, node.data+1, max))
return false;
return true;
}
}
class NodeIsTreeBST {
int data;
NodeIsTreeBST left;
NodeIsTreeBST right;
public NodeIsTreeBST NodeIsTreeBST(int data) {
NodeIsTreeBST temp = new NodeIsTreeBST();
temp.data = data;
temp.left = null;
temp.right = null;
return temp;
}
}
In Java
public class RearrangePostivieAndNegative {
public static void main(String[] args) {
int[] arr = {-5, -2, -5, -2, 4, 7, 1, 8, 0, -8};
reArrange(arr);
for(int i:arr)
System.out.print(i+" ");
}
static void reArrange(int[] arr) {
int outOfPlace = -1;
for(int i=0;i<arr.length;i++) {
if(outOfPlace>=0) {
if((arr[i]>=0 && arr[outOfPlace]<0) || (arr[i]<0 && arr[outOfPlace]>=0)) {
rightRotate(arr, outOfPlace, i);
if(i > outOfPlace + 2)
outOfPlace+=2;
else
outOfPlace = -1;
}
}
if(outOfPlace == -1) {
/*Find Out the out of place element.... :) */
if((arr[i]<0 && (i & 0x01)==1) || (arr[i]>0 && (i & 0x01)==0)) {
outOfPlace = i;
}
}
}
}
static void rightRotate(int[] arr , int outOfPlace , int curr) {
int temp = arr[curr];
for(int i=curr;i>outOfPlace;i--)
arr[i] = arr[i-1];
arr[outOfPlace] = temp;
}
}
void rearrange(int arr[], int n)
{
int outofplace = -1;
for (int index = 0; index < n; index ++)
{
if (outofplace >= 0)
{
// find the item which must be moved into the out-of-place
// entry if out-of-place entry is positive and current
// entry is negative OR if out-of-place entry is negative
// and current entry is negative then right rotate
//
// [...-3, -4, -5, 6...] --> [...6, -3, -4, -5...]
// ^ ^
// | |
// outofplace --> outofplace
//
if (((arr[index] >= 0) && (arr[outofplace] < 0))
|| ((arr[index] < 0) && (arr[outofplace] >= 0)))
{
rightrotate(arr, n, outofplace, index);
// the new out-of-place entry is now 2 steps ahead
if (index - outofplace > 2)
outofplace = outofplace + 2;
else
outofplace = -1;
}
}
// if no entry has been flagged out-of-place
if (outofplace == -1)
{
// check if current entry is out-of-place
if (((arr[index] >= 0) && (!(index & 0x01)))
|| ((arr[index] < 0) && (index & 0x01)))
{
outofplace = index;
}
}
}
}
Source : Geeks4Geeks
- shukad333 September 03, 2014import java.util.ArrayList;
import java.util.List;
public class PlusMinus {
public static void main(String[] args) {
List<Integer> arr = getPlusMinus(100);
for(int i : arr)
System.out.print(i+" ");
}
static List<Integer> getPlusMinus(int sum) {
List<Integer> list = new ArrayList<Integer>();
int i=1 ;
int s = 0;
boolean flag = false;
while(s!=sum) {
if(s+i==sum) {
list.add(i);
break;
}
if(s+i>sum)
flag = true;
if(flag)
i*=-1;
list.add(i);
s+=i;
if(flag) {
if(i<1)
--i;
else
++i;
}
else
i++;
}
return list;
}
}
package string;
public class ThreeStrings {
public static void main(String[] args) {
String StrA = "abcdecfghij" , StrB = "fedb" , c="ahij";
String temp = "" , subStr = "";
boolean startOver = false;
for(int i=0;i<StrA.length();i++) {
char ch = StrA.charAt(i);
if(StrB.contains(""+ch) || startOver) {
startOver = true;
if(c.contains(""+ch)) {
startOver = false;
temp = "";
}
else {
temp = temp+ch;
if(containsAll(temp, StrB)) {
System.out.println(temp);
break;
}
}
}
}
}
static boolean containsAll(String a , String b) {
for(int i=0;i<b.length();i++) {
if(!a.contains(b.charAt(i)+"")) {
return false;
}
}
return true;
}
}
public class StudentList {
private Marks[] allMarks;
public Marks[] getAllMarks() {
return allMarks;
}
public void setAllMarks(Marks[] allMarks) {
this.allMarks = allMarks;
}
public int totalStudents() {
return allMarks.length;
}
public int passCount() {
int tot = 0;
for(int i=0;i<totalStudents();i++) {
if(allMarks[i].isPass())
tot+=1;
}
return tot;
}
public static void main(String[] args) {
Marks[] m = new Marks[3];
m[0] = new Marks(41,33,32);
m[1] = new Marks(23, 45, 67);
m[2] = new Marks(40, 40, 45);
StudentList l = new StudentList();
l.setAllMarks(m);
System.out.println(l.totalStudents()+" "+l.passCount());
}
}
class Marks {
private int marks1;
private int marks2;
private int marks3;
private int maxMarks;
public Marks(int marks1,int marks2 , int marks3) {
this.marks1 = marks1;
this.marks2 = marks2;
this.marks3 = marks3;
this.maxMarks = this.marks1 > this.marks2 ? (this.marks1>this.marks3 ? marks1 : marks3) : (this.marks2 > this.marks3 ? this.marks2 : this.marks3);
}
public int getMarks1() {
return marks1;
}
public void setMarks1(int marks1) {
this.marks1 = marks1;
}
public int getMarks2() {
return marks2;
}
public void setMarks2(int marks2) {
this.marks2 = marks2;
}
public int getMarks3() {
return marks3;
}
public void setMarks3(int marks3) {
this.marks3 = marks3;
}
public int getMaxMarks() {
return maxMarks;
}
public void setMaxMarks(int maxMarks) {
this.maxMarks = maxMarks;
}
public boolean isPass() {
return (getMarks1()+getMarks2()+getMarks3())/3 >= 40 ? true : false;
}
public static void main(String[] args) {
Marks m = new Marks(41, 40,38);
System.out.println(m.getMaxMarks()+" "+m.isPass());
}
}
public static int dp(int[][] arr) {
int R=arr.length-1,C=arr[0].length-1;
int[][] tc = new int[R+1][C+1];
tc[0][0] = arr[0][0];
for(int i=1;i<C+1;i++)
tc[0][i] = tc[0][i-1]+arr[0][i];
for(int j=1;j<R+1;j++)
tc[j][0] = tc[j-1][0] + arr[j][0];
for(int i=0;i<R;i++)
for(int j=0;j<C;j++) {
tc[i+1][j+1] = Math.max(tc[i][j+1], tc[i+1][j])+arr[i+1][j+1];
}
return tc[R][C];
}
Solution in O(RC)
- shukad333 August 31, 2014public class MazePathMax {
public static void main(String[] args) {
int[][] arr = { { 1,5,2},
{7,9,3},
{4,9,8} ,
{3,4,5}};
System.out.println(getMaxPathSum(arr, 0, 0, arr.length-1, arr[0].length-1));
}
public static int getMaxPathSum(int[][] arr , int r , int c , int R , int C) {
if(r>R || c>C)
return -1;
if(r==R && c==C)
return arr[r][c];
int s1 = getMaxPathSum(arr, r+1, c, R, C);
int s2 = getMaxPathSum(arr, r, c+1, R, C);
return arr[r][c] + Math.max(s1, s2);
}
}
package string;
public class Compress {
public static void main(String[] args) {
System.out.println(compress("sh1u2shabc3"));
}
static String compress(String inp) {
String op = "";
int pos = 0;
boolean first = true;
for(int i=0;i<inp.length();i++) {
if((int)inp.charAt(i)>=48 && (int)inp.charAt(i)<=57) {
int a = (int)inp.charAt(i);
String st = op + inp.substring(pos,i);
String str="";
for(int j=0;j<a-48;j++) {
str += st;
}
pos = i+1;
op = str;
}
}
return op;
}
}
package string;
public class ReplaceMultipleStrings {
public static void main(String[] args) {
System.out.println(replaceMultSpace("Suha a s abc wedd"));
}
static String replaceMultSpace(String inp) {
if(inp == null || inp.isEmpty())
return null;
int len = inp.length();
for(int i=0;i<len;i++) {
if(inp.charAt(i)==' ') {
int spCount = 1;
for(int j=i+1;j<len;j++) {
if(inp.charAt(j)==' '){
spCount++;
}
else
break;
}
if(spCount>1) {
inp = inp.substring(0,i)+" "+inp.substring(i+spCount,len);
len = inp.length();
}
}
}
return inp;
}
}
- shukad333 May 26, 2019