## Time complexity of typecasting double to int in Java

double val = 500.00; int val2 = (int) val; What is the time complexity of typecasting in the previous example? Is it O(1)?

## count repeated elements in a string

The question is to find the number of consecutive occurrences of a character ‘*’ in a string. I’ve written a program for it but is there any other efficient way to solve this for(int i=0;i<...

## Problem figuring out time and space complexity?

The question was to check whether two strings are rotation of each other or not. So, here is the function I wrote for the same: bool areRotations(string s1, string s2) { int n1 = …

## Time complexity for HashMap put/get inside for?

Suppose I have the following code fragment: for(int i=0; i < n.length(); i++) { int aux = n[i]; if(map.containsKey(aux)) { map.put(aux, map.get(aux)+1); } else { map.put(...

## calculate the max length of an array such that average is less than given value

I’ve beern trying to solve this question but getting timeout for most test cases. Can anyone help me in optimising this? Problem Statement : You are given an array A of length N. You have to choose …

## HashSet look-up complexity?

A look-up operation OR contains for single can be O(n) in worst-case right ? So, for n elements look up in hashSet will be O(n^2)?