fake_Bezawada Posted June 4, 2018 Report Posted June 4, 2018 Strings can be efficiently stored as a data structure, to have efficient searching methods. A new startup is going to use this method, but they don't have much space. So they want to check beforehand how much memory will be required for their data. Following method describes the way in which this startup's engineers save the data in the structure. Suppose they have 5 strings/words: et,eq,bd,be,bdp A empty node is kept NULL, and strings are inserted into the structure one by one. Initially the structure is this: NULL After inserting "et", the structure is this: NULL | e | t After inserting "eq", the structure is this: NULL / e / \ t q After inserting "bd", the structure is this: NULL / \ e b / \ \ t q d After inserting "be", the structure is this: NULL / \ e b / \ / \ t q e d After inserting "bdp", the structure is this: NULL / \ e b / \ / \ t q e d \ p Therefore a total of 8 nodes are used here. Input: First line contains N, the number of strings they have. Each of the next N lines contain one string. Each string consists only of lowercase letters. Output: Print the required number of nodes. **Constraints: 1≤N≤105 Length of each string ≤30 Note: No two strings are same, though one string could be prefix of another. SAMPLE INPUT 5 et eq bd be bdp SAMPLE OUTPUT 8 Quote
fake_Bezawada Posted June 4, 2018 Author Report Posted June 4, 2018 @karthikn raa uncle ippude try chesa 2/10 inputs through ayayi nee code kooda veyyi chudam enni inputs through aythayo Quote
fake_Bezawada Posted June 4, 2018 Author Report Posted June 4, 2018 @BaabuBangaram come here you're the only one who can solve this Quote
BaabuBangaram Posted June 4, 2018 Report Posted June 4, 2018 35 minutes ago, fake_Bezawada said: @BaabuBangaram come here you're the only one who can solve this trees use cheyya nenu.....so no idea..... Quote
karthikn Posted June 4, 2018 Report Posted June 4, 2018 6 hours ago, fake_Bezawada said: @karthikn raa uncle ippude try chesa 2/10 inputs through ayayi nee code kooda veyyi chudam enni inputs through aythayo Constructing trie is the question. Chesta evening Quote
Popkatapetapotapulti Posted June 4, 2018 Report Posted June 4, 2018 I dont think this is a difficult problem. Just create a trie data structure and in your insert method increment a global counter variable(only when you are creating a node). Difficultly epudu vastundi ante if he/she insists to not create a trie ds...but I highly doubt if it can be solved using DP. Kasepu alochinchi malli post chesta @Pichkaari neku ede adigaru anukunta kada..or some version of this Quote
Pichkaari Posted June 4, 2018 Report Posted June 4, 2018 1 hour ago, Popkatapetapotapulti said: I dont think this is a difficult problem. Just create a trie data structure and in your insert method increment a global counter variable(only when you are creating a node). Difficultly epudu vastundi ante if he/she insists to not create a trie ds...but I highly doubt if it can be solved using DP. Kasepu alochinchi malli post chesta @Pichkaari neku ede adigaru anukunta kada..or some version of this Yeah smiliar e .. but adhi NLP related question anukunta bhayya. Quote
Popkatapetapotapulti Posted June 4, 2018 Report Posted June 4, 2018 17 minutes ago, Pichkaari said: Yeah smiliar e .. but adhi NLP related question anukunta bhayya. ok Quote
fake_Bezawada Posted June 5, 2018 Author Report Posted June 5, 2018 20 hours ago, karthikn said: Constructing trie is the question. Chesta evening nenu already chesesa my code is running good but not for all test cases 3/10 through ayayi Quote
fake_Bezawada Posted June 5, 2018 Author Report Posted June 5, 2018 13 hours ago, Pichkaari said: Yeah smiliar e .. but adhi NLP related question anukunta bhayya. NLP ante Quote
fake_Bezawada Posted June 5, 2018 Author Report Posted June 5, 2018 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; public class TestClass { static int count=0; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int noOfInputs = Integer.parseInt(br.readLine()); String[] strInputs=new String[noOfInputs]; for(int i=0;i<noOfInputs;i++) { String input=br.readLine(); strInputs[i]=input; } doProcess(strInputs); } private static void doProcess(String[] splInput) { HashMap<String,String> result=new HashMap<String,String>(); for(String s:splInput) { for(int i=0;i<s.length();i++) { if(i!=0) { String value=String.valueOf(s.charAt(i)); if(result.keySet().contains(String.valueOf(s.charAt(0)))) { if(String.valueOf(result.get(String.valueOf(s.charAt(0))).charAt(0))!=value) { value =value+result.get(String.valueOf(s.charAt(0))); result.put(String.valueOf(s.charAt(0)),value); } }else { result.put(String.valueOf(s.charAt(0)),value); } } } } getFinalresult(result); } private static void getFinalresult(HashMap<String, String> result) { int count=0; for(String s:result.keySet()) { count=count+result.get(s).length()+1; } System.out.println(count+1); } } Quote
Pichkaari Posted June 5, 2018 Report Posted June 5, 2018 6 hours ago, fake_Bezawada said: NLP ante Natural Language Processing. AI related dude. Quote
fake_Bezawada Posted June 6, 2018 Author Report Posted June 6, 2018 12 hours ago, Pichkaari said: Natural Language Processing. AI related dude. eppudu vinaledu papachak uncle chustanu adhi kooda Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.