We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
input<-readLines("stdin")# Extract n and q from the first linefirst_line<-strsplit(input[1]," ")[[1]]n<-as.integer(first_line[1])q<-as.integer(first_line[2])# Extract the strings<-input[2]# Process each queryfor(iin3:(3+q-1)){query_line<-strsplit(input[i]," ")[[1]]l<-as.integer(query_line[1])+1#Convertto1-basedindexingr<-as.integer(query_line[2])+1#Convertto1-basedindexing# Extract the substringsubstring<-substr(s,l,r)# Initialize a set to store unique substringsunique_substrings<-new.env(hash=TRUE)# Generate all possible substringslen_substring<-nchar(substring)for(lenin1:len_substring){for(startin1:(len_substring-len+1)){current_sub<-substr(substring,start,start+len-1)unique_substrings[[current_sub]]<-TRUE}}# Count distinct substringsdistinct_count<-length(unique_substrings)# Print the resultcat(distinct_count,"\n")}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
How Many Substrings?
You are viewing a single comment's thread. Return to all comments →
THIS CODE WORKS GUYS😎😎 C++