instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a Java code snippet to take input from the user and print the result. The input should be a string of numbers separated by commas, and the program should calculate the sum of all the numbers in the string. However, the program should also handle cases where the input string contains negative numbers. In such case... | codefeedback |
Create a HTML page with a form containing two input boxes, one to enter a number and another to enter an operator (+, -, *, /). Additionally, add client-side validation to ensure that the number entered is a positive integer and display an appropriate error message if it is not.
Modify the code to also validate the o... | codefeedback |
Create an Apache Spark program written in Scala that takes in an RDD of integers and returns a new RDD where each element is the product of its immediate neighbors. For example, given the input RDD [1, 2, 3, 4], the output RDD should be [2, 3, 8, 6].
Note: The first and last elements in the input RDD should only have ... | codefeedback |
Update the following code to be Python 3 compatible and optimize it to print "Welcome to the Program." without using the print statement. Additionally, the code should be optimized to use a single line of code. | codefeedback |
In Python, write a program to remove all duplicates from a given list of integers, sort the list in ascending order, and return the count of unique numbers in the list. The program should also handle negative integers and zero. | codefeedback |
Describe a complete algorithm for sorting n integers in descending order using only bubble sort algorithm. | codefeedback |
Create a Python script to find the greatest common divisor (GCD) of a pair of integers. The time complexity of the solution should not exceed O(log(min(a,b))) where a and b are the input integers. Additionally, the space complexity of the solution should be O(1) (i.e. constant space).
Number 1: 123456789
Number 2: 98... | codefeedback |
Create an algorithm that takes in an array of positive integers and a target number, and returns true if any three distinct integers in the array add up to the target number. Otherwise, return false.
Example:
array = [4, 2, 5, 7, 9]
target = 16
Expected output:
True | codefeedback |
Design a class in Java to represent a person's contact information like name, phone number, email address, and home address. The home address should include the street name, city, state, and postal code. The class should have methods to validate the phone number and email address. Additionally, the class should include... | codefeedback |
Implement a SQL query to count the number of students who are from North America (NA), have a grade higher than 80, and have taken at least 3 courses. | codefeedback |
Adapt the following Java program to print the smallest and second smallest numbers from an array of numbers. You must solve the problem using only a single loop and without using any additional data structures or sorting algorithms. | codefeedback |
Create a JavaScript program that generates the Fibonacci sequence up to a given number provided by the user. The program should print out the Fibonacci sequence in reverse order and also calculate the sum of all the numbers in the sequence. Additionally, the program should implement a recursive function to calculate ea... | codefeedback |
Create a function in JavaScript which prints all twin prime numbers up to a given number.
(Note: Twin prime numbers are a pair of prime numbers that differ by 2, for example, (3, 5), (11, 13), (17, 19), etc.)
Additionally, make sure to implement the function using a recursive approach rather than an iterative one. | codefeedback |
Transform the following C code into Java code. Make sure to handle any potential errors or exceptions that may occur.
```c
int array[100];
int i, sum = 0;
for (i = 0; i < 100; i++)
sum += array[i];
```
#Erroneous Reference#
Below is a piece of erroneous Java code that is meant to perform the same functionality as ... | codefeedback |
Create a data structure suitable for storing a list of scores for a game, where each score can have an associated player name, timestamp, and level of difficulty. Implement methods to add a new score, retrieve the highest score, retrieve the average score, and retrieve the scores in chronological order. | codefeedback |
Implement an efficient algorithm in Python to find the GCD (Greatest Common Divisor) of two numbers without using any built-in GCD functions. Your algorithm should have a time complexity of O(log(min(a,b))), where a and b are the given numbers. Additionally, your algorithm should be able to handle extremely large numbe... | codefeedback |
Create a function in Python to remove all characters other than letters and numbers from a string. Additionally, any letter that is capitalized should be converted to lowercase, and any duplicate letters or numbers should be removed, so that only unique letters and numbers remain in the string. The function should have... | codefeedback |
Create a Python function which takes a given string and replaces all its characters with the next consecutive character. The function should handle both uppercase and lowercase letters separately, and should wrap around from 'z' to 'a' or 'Z' to 'A' when necessary. The function should also ignore any non-alphabetic cha... | codefeedback |
Write a Java program for removing all white spaces from a given string. However, the program should also remove any leading or trailing white spaces in the string. Additionally, the program should convert all uppercase letters to lowercase and all lowercase letters to uppercase within the string. The program should als... | codefeedback |
Create a JavaScript function that takes a string as an argument, reverses it, and removes all duplicate characters, returning the result. The input string will only contain lowercase letters and have a maximum length of 100 characters. Additionally, the function should ignore any vowels in the input string when removin... | codefeedback |
Create a SQL query to add a new column to a table called "students" which contains student id numbers, names, and their corresponding grade levels. The grade levels should be represented by the following values: "Freshman", "Sophomore", "Junior", "Senior". Additionally, the grade levels should be calculated based on th... | codefeedback |
Write a script in Python to sort a list of words alphabetically in descending order, while ignoring case sensitivity. The script should also remove any duplicate words from the list before sorting. Additionally, the script should only use built-in functions and not any external libraries or modules. | codefeedback |
Write a shell command to print out the environment variable $PATH, but only display the directories that are writable by the current user. Additionally, the command should exclude any hidden directories (directories whose names start with a dot). | codefeedback |
Write a SQL query to update the "job" column of the "employees" table to "engineer" for all rows with the following conditions: the "department" column value must be "IT", the "salary" column value must be greater than $50,000, and the "age" column value must be less than 40. | codefeedback |
Write a function in Python to take a string as input and return a dictionary with the count of each unique vowel in the string. The function should ignore case and consider only the following vowels: 'a', 'e', 'i', 'o', 'u'. If the string does not contain any of these vowels, the function should return an empty diction... | codefeedback |
Create a function in Python to split a given string into a list of strings using a comma as a delimiter. However, make sure to handle cases where there are multiple consecutive spaces in the string and remove any leading or trailing spaces. Additionally, the function should ignore any commas that are inside double quot... | codefeedback |
Write a function in Python that will take two integers as inputs and compute their average. However, the function should only consider integers within a given range (inclusive) for the calculation.
The range is defined by two additional inputs: range_start and range_end.
For example, if int1 = 10, int2 = 15, range_st... | codefeedback |
Write a function to calculate the sum of the elements of an array with float values, excluding any negative values and rounding the final sum to two decimal places. Additionally, the function should also exclude any values that are greater than 100. | codefeedback |
Create a Python function which takes a nested dictionary and prints the contents of the dictionary in a human readable format, with each key-value pair indented according to its level of nesting. Additionally, implement the following features:
1. Handle nested dictionaries and lists: If a value in the dictionary is an... | codefeedback |
Add a method to the Customer class to print out the customer's name, age, email, as well as their shipping address and billing address. | codefeedback |
Create a function in PHP to retrieve the contents of a given URL using the cURL library and display the HTML title tag of the retrieved webpage. Additionally, the function should also extract and display the meta description tag of the webpage. The function should handle cases where the URL is not valid or the webpage ... | codefeedback |
Implement a function in any programming language that takes an integer n as input and prints the sum of all prime numbers up to n.
Requirements:
- The function should have a time complexity of O(n^(3/2)).
- The function should not use any external libraries or built-in functions to check for prime numbers.
- The funct... | codefeedback |
What is the principal difference between a linked list and a dynamic array? Discuss the time and space complexities of common operations for each data structure and explain why the code provided is erroneous and how it relates to the principal difference.
Erroneous code:
```
LinkedList<int> myList = new LinkedList<int... | codefeedback |
Provide a solution to print the following string in reverse order while excluding any vowels and special characters. Additionally, the solution should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the string.
String = "Hello, world!" | codefeedback |
Build a program in Python to check if a given number is a prime number or not, but you are not allowed to use the modulus operator (%) to check for divisibility. Instead, you should implement your own method to determine if a number is divisible by another number. | codefeedback |
Write some HTML+CSS to create a navigation bar for a website with the following requirements:
- The navigation bar must have a fixed position at the top of the page and remain visible even when scrolling.
- The navigation bar must have a dropdown menu for the "Products" section, displaying sub-categories such as "Elect... | codefeedback |
Write a function to calculate the string length in a given string, but you cannot use the built-in function to calculate the length of a string. Additionally, you are not allowed to use any loops or recursion in your solution.
String: "Hello, World!" | codefeedback |
Create a function in Java to detect if an input string is a palindrome, but with the following additional constraints:
- The function must be case-insensitive, meaning that "racecar" and "Racecar" should be considered palindromes.
- The function must ignore all non-alphanumeric characters, such as spaces, punctuation, ... | codefeedback |
Create a function in Python that takes in a positive integer N as input. The function should generate an array of N random strings, each consisting of lowercase alphabets and have a length between 5 and 10 characters. The function should ensure that at least one string in the array contains at least one uppercase lette... | codefeedback |
Write a JavaScript code snippet to set a value for a cookie, but the cookie must be encrypted using AES encryption algorithm with a randomly generated key and initialization vector (IV) before being stored. The encrypted cookie value should also be base64 encoded.
Furthermore, the code should include a function to dec... | codefeedback |
Write a Python program to find the closest pair of numbers in a given array to a given number. The array and the number will always be provided. However, if the array has less than 2 elements, the program should return an error message. If the given number is not present in the array, the program should return the clos... | codefeedback |
Write a program in Python that takes an integer input from the user and uses a while loop to calculate the factorial of that number. The program should validate the input to ensure it is a positive integer and prompt the user to enter a valid input if necessary. Additionally, the program should handle the case when the... | codefeedback |
How to delete a specific item from a Python dictionary if the dictionary has nested dictionaries and the deletion should be done recursively, while maintaining a time complexity of O(n) and a space complexity of O(1)? | codefeedback |
Write a code to create a web page with a responsive navigation bar. The navigation bar should have a logo on the left, and a set of links on the right. When the screen size is small, the links should be collapsed into a dropdown menu accessible through a hamburger icon. The logo and links should be styled with CSS, and... | codefeedback |
Sort the following array of numbers [7,2,4,1,9] in descending order using JavaScript.
Additional requirements:
- You are not allowed to use any built-in sorting functions or libraries.
- You must implement your own sorting algorithm.
- Your sorting algorithm should have a time complexity of O(n^2).
- Your sorting alg... | codefeedback |
Create a program in Java that finds the maximum element in an array. However, instead of using a built-in function or method, you must implement your own algorithm to find the maximum element.
Your algorithm should not use any sorting functions, loops, or recursion. Instead, you must find the maximum element using a b... | codefeedback |
Given an array of integers, write an algorithm to reorder the array so that all the prime numbers appear before all the non-prime numbers, while maintaining the relative order of the prime numbers and the relative order of the non-prime numbers. Your algorithm should have a time complexity of O(n) and should not use an... | codefeedback |
Create a RESTful API in Node.js that returns the Fibonacci sequence up to a given number when it is invoked. The API should accept a positive integer as a parameter and return a JSON response containing the Fibonacci sequence up to that number. Additionally, the API should implement rate limiting, allowing only a maxim... | codefeedback |
How to generate a random number between two given numbers without using any built-in random number generator functions or libraries in Python? Additionally, ensure that the generated random number is unique and not previously generated within the same program execution. | codefeedback |
Write a method to find the maximum number of consecutive subarrays in an array such that the sum of each subarray is equal to a specified number. The subarrays must have a length of at least 4.
arr = [1, 2, 3, 4, 5, 6, 7] | codefeedback |
Write a JavaScript function to calculate the length of a given string without using the built-in `length` property or any other string manipulation methods, and with a time complexity of O(n). | codefeedback |
You are given a dictionary in Python containing student names as keys and their corresponding scores as values. Write a function that takes this dictionary as input and returns a new dictionary with the students sorted in descending order based on their scores.
Additionally, modify the function to handle the case wher... | codefeedback |
Code a for loop that iterates over a list of numbers and stores the tripled value of each number in another list. The original list should not be modified. Additionally, the solution should have a time complexity of O(n) and a space complexity of O(n). The solution should not use any built-in functions or methods that ... | codefeedback |
Explain in detail what is a pointer in C++. Provide a practical example of using a pointer in a C++ program and explain the potential risks and benefits of using pointers in programming. Additionally, discuss the differences between stack and heap memory allocation and when to use each. Finally, provide an example wher... | codefeedback |
Write a function that takes in a list of strings and a character as input, and returns a single string that joins all the strings together using the given character as a separator. The time complexity of your solution should be O(n), where n is the total number of characters in all the strings combined.
#Example#
Inp... | codefeedback |
Code a for loop that iterates over a list of strings and capitalizes the first letter of each string. However, make sure to handle cases where a string starts with a number or special character. If a string starts with a number or special character, skip capitalizing the first letter and instead capitalize the second l... | codefeedback |
Create a web page using HTML, CSS, and JavaScript that contains a heading, a button, and a form. When the button is clicked, the form should be validated to check if all required fields are filled out. If any required fields are empty, display an error message next to each empty field. Additionally, the button should c... | codefeedback |
How can you remove all the empty strings from a list while maintaining the order of the remaining elements and without using any built-in functions or methods in the programming language you are using? | codefeedback |
Given a list of strings, create a Python3 program that counts the number of strings that start with the letter 'a' and have a length greater than 5. Additionally, the program should also check if the string contains at least two vowels (aeiou) and at least two consonants (non-vowels).
Example Input:
example_list = ["A... | codefeedback |
Implement a function that generates the nth Fibonacci number using a loop, but also handles negative values of n by returning -1 for invalid inputs. Additionally, optimize the algorithm to have a time complexity of O(n). | codefeedback |
Create a function in Python that takes a sentence as input and returns a dictionary of each word and its frequency in the sentence. The function should ignore punctuation marks, consider words with different letter casing as the same word, and also exclude common words such as articles, prepositions, and conjunctions.
... | codefeedback |
Write a function to convert an anagram of a string to a dictionary. The anagram must contain only lowercase alphabetic characters and must not exceed a length of 15. The resulting dictionary should only include words that have at least 5 unique letters and have a length of at least 6 characters. The function should han... | codefeedback |
Given a list of strings, create a Python function that sorts them in alphabetical order. Additionally, the function should ignore the case of the letters while sorting. The function should return the sorted list as output. The input list may contain duplicate strings, and the function should handle and preserve the dup... | codefeedback |
Create a function in Java that takes two strings and returns an integer that describes the number of characters they share in common. The function should consider both uppercase and lowercase characters as the same.
string1 = "Hello"
string2 = "world"
Example:
Input:
string1 = "Hello"
string2 = "world"
Output:
1
Ex... | codefeedback |
Calculate the Euclidean distance between two arrays, where each array contains 1,000,000 randomly generated numbers between 0 and 1,000,000.
Note: The time complexity should not exceed O(n), where n is the number of elements in each array. | codefeedback |
How can you flatten a list of lists, ensure that all elements in the flattened list are unique, and sort the elements in ascending order? | codefeedback |
Write SQL code to remove duplicates from a database table, but do not use any built-in functions or temporary tables. Additionally, the solution must be efficient and have a time complexity of O(n log n).
Table name: Items
Columns: ID, Name | codefeedback |
Write a program that generates a random permutation of an array of integers. The program should follow these steps:
1. Take an input from the user for the length of the array.
2. Generate a random number between 1 and 1000 and assign it to a variable `seed`.
3. Initialize an empty array `numbers`.
4. Generate `length`... | codefeedback |
Create a class in C++ called Point that represents a point in the two-dimensional space. The class should have the following features:
1. Private member variables to store the x-coordinate and y-coordinate of the point.
2. Public member functions to:
- Set the x-coordinate and y-coordinate of the point.
- Get th... | codefeedback |
Find the frequency of a given phrase in the text, considering case sensitivity, punctuation marks, and the position of the phrase in the text.
text = "This is a phrase that I want to find the frequency of. The phrase, phrase, is important! This phrase should not be counted if it appears as a substring within another w... | codefeedback |
Write code in C++ to reverse an array of elements without using any additional arrays or data structures. Your solution should have a time complexity of O(n) and a space complexity of O(1). Additionally, you are not allowed to use any built-in functions or libraries for array manipulation or string manipulation. | codefeedback |
Get the length of the given string, excluding any whitespace characters. Additionally, the program should ignore any punctuation marks and count only alphanumeric characters.
string = "Summer is here! Are you ready?" | codefeedback |
Write a function that prints the same string n times consecutively, where n is a positive integer greater than 1. The function should take two arguments: the string to be printed and the value of n. The time complexity of the function should be O(n), and the space complexity should be O(1).
Example:
Input: "Hello Worl... | codefeedback |
Construct a regular expression that extracts substrings that match the pattern "AAA_BBB_CCC" and are followed by either "DDD" or "EEE" and preceded by a specific string "XYZ". | codefeedback |
You are given an XML structure representing scores of different players in a game. Each <score> element contains the player's name and their score. Your task is to extract the value of the given key for the player with the highest score.
To solve this problem, you can follow these steps:
1. Parse the given XML struct... | codefeedback |
Create a SQL query to get the count of students who have achieved the highest marks in each subject, excluding students who have failed any other subject. Assume that the table structure is as follows:
Table Name: STUDENTS
Table Columns: NAME (string); SUBJECT (string); MARKS (int); STATUS (string)
The STATUS column c... | codefeedback |
Implement Naive Bayes for classification on a large dataset with multiple features and classes. Additionally, incorporate Laplace smoothing to handle zero probabilities. However, you must also handle missing values in the dataset by implementing a suitable method for imputation. | codefeedback |
Implement a deep convolutional neural network with batch normalization and residual connections for image regression. Additionally, add dropout regularization to improve generalization and introduce data augmentation techniques to increase the size and diversity of the training dataset. | codefeedback |
Write a program that takes a JSON data as input and finds the values of the keys 'category' and 'difficulty'. The JSON data will have the following structure:
{
"status": "SUCCESS",
"message": "",
"data": {
"category": "Mathematics",
"difficult": "Easy",
"questions": [
{... | codefeedback |
Write code in Java to calculate the minimum number of coins needed to make change for a given amount, but with the constraint that you can only use each coin denomination once. Additionally, you are not allowed to use a coin denomination that is larger than the remaining amount to be changed. Coin denominations: [1, 2,... | codefeedback |
Write a function in JavaScript to set the background color of a web page to a randomly generated color, but the generated color should be a shade of blue. The shade of blue should have a hue value between 180 and 240, a saturation value between 50% and 100%, and a lightness value between 20% and 80%. | codefeedback |
Create a `Person` class that represents a person's information, including their name, age, gender, and contact information. Ensure that the name attribute is restricted to only accept alphabetical characters and has a maximum length of 50 characters. The age attribute should only accept integer values between 18 and 10... | codefeedback |
Given an input string and a pattern, find the first index of the pattern in the string. The pattern can contain wildcards represented by the '*' character, which can match any sequence of characters (including an empty sequence). The pattern can also contain '?' character, which can match any single character. In addit... | codefeedback |
Write a function to delete a node from the given linked list, where the linked list is sorted in ascending order. The function should also handle cases where the node to delete is the head or tail of the linked list.
Linked list: 1 --> 3 --> 5 --> 7 --> 9
Node to delete: 5
Additional constraints:
- The function shou... | codefeedback |
How can you use the modulo operator to print all prime numbers in the range of 1 to 100, using a nested loop and a time complexity of O(n^2)? | codefeedback |
Demonstrate how to use multiple if-else blocks to control the execution sequence of a program. Additionally, include multiple nested if statements within the else blocks to further manipulate the program flow. The program should have a time complexity of O(n), where n is the size of the input data. | codefeedback |
Generate a function in Java to calculate the sum of all prime digits for any given integer, without using any loops or recursion.
Additional requirement: The function should have a space complexity of O(1). | codefeedback |
Construct a function in Python that takes a list of integers and returns the median of the elements in the list. The function should handle both odd and even length lists. If the list has an even length, the median should be the average of the two middle elements. Additionally, the function should handle cases where th... | codefeedback |
Increase the difficulty by adding more reasoning steps to solve the problem.
Create a class in C++ called "PreciseNumber" that defines a number as a double value and includes the following additional requirements:
1. The class should include a constructor that takes in a string representation of a number and converts... | codefeedback |
Create a function which determines if a given number is a palindrome, while also considering negative numbers. The function should handle large numbers efficiently and without converting them to strings.
-45676458 | codefeedback |
Given an array of integers, separate the odd and even numbers, and return a list of two different arrays, one for even numbers and one for odd numbers. The arrays should be sorted in ascending order. The length of the array should be at least 5 and at most 10^6. The maximum value of each integer in the array should be ... | codefeedback |
Write a SELECT statement that retrieves the first name, last name, and salary of all employees whose salary is above the average salary of all employees and whose hire date is within the last 6 months, sorted in descending order of salary. | codefeedback |
Provide the JavaScript code required to navigate to a page when the page is loaded, but the URL of the page to navigate to should be determined dynamically based on the user's input. Additionally, the code should include error handling to display an error message if the user's input is invalid or if the navigation fail... | codefeedback |
Write a function that takes two strings as parameters and returns a new string that has the characters of the second string appended to the first string. Additionally, the function should remove any duplicate characters from the resulting string.
For example, given the strings "hello" and "world", the function should ... | codefeedback |
Write a JavaScript program to find all the words in a string which start with a specific letter and are followed by a vowel, and are not preceded or followed by any punctuation or whitespace characters. Consider handling cases where the specific letter can be either lowercase or uppercase. | codefeedback |
Compose a piece of HTML code that uses a form to let the user input an email address and password. Upon submission, validate the email address to ensure it follows the correct format (i.e., contains an '@' symbol and a valid domain). Additionally, implement password validation by checking if the password is at least 8 ... | codefeedback |
Write a JavaScript program to make a deep clone of an object, ensuring that all properties of the cloned object are in uppercase, sorted in descending order, and any nested objects are also deeply cloned. | codefeedback |
Reverse the characters in each word of a sentence stored as a list in Python. Additionally, implement the solution using only constant extra space. | codefeedback |
Retrieve the elements in an array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] where the index is a prime number and the element itself is a prime number. | codefeedback |
Convert the following string "10 10 20 20 30" into a list of integers. The resulting list must not contain any duplicate values. Additionally, you should ensure that the elements in the resulting list are sorted in ascending order. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.